示例#1
0
 public static int markComponent(OrientedGraph graph, int startNode, int mark, int oldSize) {
   if (graph.getMark(startNode) != 0) {
     return oldSize;
   }
   int size = oldSize + 1;
   graph.mark(startNode, mark);
   for (int parentIndex : graph.getParents(startNode)) {
     size = markComponent(graph, parentIndex, mark, size);
   }
   return size;
 }
示例#2
0
 public static void topologicalSort(
     List<Integer> sortedNodes, OrientedGraph graph, int startNode) {
   if (graph.getMark(startNode) != 0) {
     return;
   }
   graph.mark(startNode, 1);
   for (int childIndex : graph.getChildren(startNode)) {
     topologicalSort(sortedNodes, graph, childIndex);
   }
   sortedNodes.add(startNode);
 }