public static void Sort(Graph g) { TopologicalSort.s_Graph = g; TopologicalSort.s_SortedNodes = new List <Node>(); TopologicalSort.s_NodeStates = new Dictionary <Node, TopologicalSort.NodeState>(); foreach (Node current in g.nodes) { TopologicalSort.Visit(current); } }
private static void Visit(Node n) { if (!TopologicalSort.s_NodeStates.ContainsKey(n)) { TopologicalSort.s_NodeStates[n] = TopologicalSort.NodeState.Visited; foreach (Edge current in n.outputEdges) { TopologicalSort.Visit(current.toSlot.node); } TopologicalSort.s_SortedNodes.Add(n); } }