1 25 package classycle.graph; 26 27 55 public abstract class GraphProcessor { 56 64 public void deepSearchFirst(Vertex[] graph) { 65 initializeProcessing(graph); 66 for (int i = 0; i < graph.length; i++) { 67 graph[i].reset(); 68 } 69 70 for (int i = 0; i < graph.length; i++) { 71 if (!graph[i].isVisited()) { 72 process(graph[i]); 73 } 74 } 75 finishProcessing(graph); 76 } 77 78 79 protected void process(Vertex vertex) { 80 vertex.visit(); 81 processBefore(vertex); 82 for (int i = 0, n = vertex.getNumberOfOutgoingArcs(); i < n; i++) { 83 processArc(vertex, vertex.getHeadVertex(i)); 84 } 85 processAfter(vertex); 86 } 87 88 92 protected abstract void initializeProcessing(Vertex[] graph); 93 94 98 protected abstract void processBefore(Vertex vertex); 99 100 105 protected abstract void processArc(Vertex tail, Vertex head); 106 107 111 protected abstract void processAfter(Vertex vertex); 112 113 117 protected abstract void finishProcessing(Vertex[] graph); 118 } | Popular Tags |