File tree Expand file tree Collapse file tree 3 files changed +30
-33
lines changed Expand file tree Collapse file tree 3 files changed +30
-33
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -124,4 +124,34 @@ public int compareTo(Node other) {
124
124
return Integer .compare (this .id , other .id );
125
125
}
126
126
}
127
+
128
+ public static void main (String [] args ) {
129
+ System .out .println ("Creating Tree" );
130
+ Tree tree = new Tree (3 , 3 );
131
+
132
+ System .out .println ("Using recursive DFS :" );
133
+ tree .dfsRecursive ();
134
+
135
+ System .out .println ("Using stack-based DFS :" );
136
+ tree .dfsStack ();
137
+
138
+ System .out .println ("Using queue-based BFS :" );
139
+ tree .bfsQueue ();
140
+
141
+ System .out .println ("Using post-order recursive DFS :" );
142
+ tree .dfsRecursivePostOrder ();
143
+
144
+
145
+ // Uncommenting the following 2 lines will result in an exception thrown because at least one Node of the Tree has more than 2 children and therefor a DFSRecursiveInorderBinary doesn't work.
146
+ System .out .println ("Using in-order binary recursive DFS : (fail)" );
147
+ tree .dfsRecursiveInOrderBinary ();
148
+
149
+ tree = new Tree (3 , 2 );
150
+ System .out .println ("Using in-order binary recursive DFS : (succeed)" );
151
+ tree .dfsRecursiveInOrderBinary ();
152
+
153
+
154
+ System .out .println ("" );
155
+ }
156
+
127
157
}
Original file line number Diff line number Diff line change @@ -330,8 +330,6 @@ Here is a video describing tree traversal:
330
330
{% sample lang="java" %}
331
331
##### Tree.java
332
332
[ import, lang:"java"] ( code/java/Tree.java )
333
- ##### MainClass.java
334
- [ import, lang:"java"] ( code/java/MainClass.java )
335
333
{% sample lang="js" %}
336
334
[ import, lang:"javascript"] ( code/javascript/tree.js )
337
335
{% sample lang="py" %}
You can’t perform that action at this time.
0 commit comments