11package org .algorithm_visualizer ;
22
3+ import org .algorithm_visualizer .*;
4+
35class Test {
6+ static GraphTracer tracer = new GraphTracer ();
7+ tracer .log (new LogTracer ());
8+ static int G [][] = { // G[i][j] indicates whether the path from the i-th node to the j-th node exists or not
9+ {0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
10+ {0 , 0 , 0 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 },
11+ {0 , 0 , 0 , 0 , 0 , 1 , 1 , 0 , 0 , 0 , 0 },
12+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 0 , 0 },
13+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 },
14+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
15+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
16+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
17+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
18+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
19+ {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 },
20+ };
21+
22+ static void DFS (int node , int parent ) { // node = current node, parent = previous node
23+ tracer .visit (node , parent ).delay ();
24+ for (int i = 0 ; i < G [node ].length ; i ++) {
25+ if (G [node ][i ] == 1 ) { // if current node has the i-th node as a child
26+ DFS (i , node ); // recursively call DFS
27+ }
28+ }
29+ }
30+
431 public static void main (String [] args ) {
5- ChartTracer chartTracer = new ChartTracer ();
6- chartTracer .set (new Object []{});
7- Layout .setRoot (new VerticalLayout (new Commander []{chartTracer }));
32+ tracer .set (G ).layoutTree (0 ).delay ();
33+ DFS (0 , -1 );
834 }
9- }
35+ }
0 commit comments