Added postorder tree traversal · pythonpeixun/AlgorithmVisualizer@75115bf · GitHub
Skip to content

Commit 75115bf

Browse files
committed
Added postorder tree traversal
1 parent 1b83294 commit 75115bf

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

algorithm/tree/binary_tree_traversal/desc.json

Lines changed: 1 addition & 0 deletions
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var index = 0;
2+
3+
function inorder ( root , parent ) {
4+
if (root === -1) {
5+
logger._print( 'No more nodes. Backtracking.' )._wait ();
6+
return;
7+
}
8+
9+
logger._print( 'Reached ' + root);
10+
treeTracer._visit ( root , parent )._wait ();
11+
12+
logger._print ( ' Going left from ' + root )._wait ();
13+
inorder(T[root][0], root);
14+
15+
logger._print ( ' Going right from ' + root )._wait ();
16+
inorder(T[root][1], root);
17+
18+
logger._print( 'Printing ' + root);
19+
treeTracer._leave ( root );
20+
arrayTracer._notify ( index++, root )._wait();
21+
}
22+
23+
inorder ( 5 ); // node with key 5 is the root
24+
logger._print( 'Finished' );
Lines changed: 32 additions & 0 deletions

0 commit comments

Comments
 (0)