Professional Documents
Culture Documents
Chap14 HW Graphs
Chap14 HW Graphs
CSCI-313
HW#14
C-14.37
// Remove the edge from the outgoing edges of the origin vertex
origin.getOutgoing().remove(destination);
// Remove the edge from the incoming edges of the destination vertex
destination.getIncoming().remove(origin);
// Remove the reverse edge from the outgoing edges of the destination
vertex
destination.getOutgoing().remove(origin);
// Remove the reverse edge from the incoming edges of the origin vertex
origin.getIncoming().remove(destination);
-----------------------------------------------------------------------------------
------------------------------------------------------------
C-14.42
if (cycle.contains(neighbor)) {
// Found a cycle
int index = cycle.indexOf(neighbor);
cycle.subList(0, index).clear(); // Remove the elements before the
cycle start
return true;
}
cycle.remove(current);
return false;
}
-----------------------------------------------------------------------------------
------------------------------------------------------------
C-14.50
import java.util.*;
visited.add(start);
queue.offer(start);
while (!queue.isEmpty()) {
Vertex<V> current = queue.poll();
System.out.println(current.getElement()); // Process the vertex (e.g.,
print its element)
if (!visited.contains(neighbor)) {
visited.add(neighbor);
queue.offer(neighbor);
}
}
}
}
}