1- package org .algorithm_visualizer ;
1+ package org .algorithm_visualizer ;// import visualization libraries {
22
3- import org . algorithm_visualizer .*;
3+ // }
44
55class 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 },
6+ // define tracer variables {
7+ Array2DTracer array2dTracer = new Array2DTracer ("Grid" );
8+ LogTracer logTracer = new LogTracer ("Console" );
9+ // }
10+
11+ // define input variables
12+ String [] messages = {
13+ "Visualize" ,
14+ "your" ,
15+ "own" ,
16+ "code" ,
17+ "here!" ,
2018 };
2119
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- }
20+ // highlight each line of messages recursively
21+ void highlight (int line ) {
22+ if (line >= messages .length ) return ;
23+ String message = messages [line ];
24+ // visualize {
25+ logTracer .println (message );
26+ array2dTracer .selectRow (line , 0 , message .length () - 1 );
27+ Tracer .delay ();
28+ array2dTracer .deselectRow (line , 0 , message .length () - 1 );
29+ // }
30+ highlight (line + 1 );
31+ }
32+
33+ Test () {
34+ // visualize {
35+ Layout .setRoot (new VerticalLayout (new Commander []{array2dTracer , logTracer }));
36+ array2dTracer .set (messages );
37+ Tracer .delay ();
38+ // }
39+ highlight (0 );
2940 }
3041
3142 public static void main (String [] args ) {
32- tracer .set (G ).layoutTree (0 ).delay ();
33- DFS (0 , -1 );
43+ new Test ();
3444 }
35- }
45+ }
0 commit comments