Topological Sort


Colors: Blue: nodes that have been ordered Black: Nodes yet to be ordered


Algorithm

All nodes with no incoming arcs (indegree of 0) are removed from the graph and labeled. The algorithm continues to remove nodes with 0 indegree until either the graph is empty or there are no more nodes without incoming arcs. The first case results in a linear ordering of the nodes while the second indicates a cycle, which prevents a linear traversal of the nodes.

Sollin

Code
TopoSort.java
Node.java
Edge.java
Graph.java
MainApplet.java