forked from spencer-luo/DataStructure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
36 lines (31 loc) · 782 Bytes
/
Copy pathOrder.java
File metadata and controls
36 lines (31 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package datastructure.tree;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.List;
public class Order {
public void preOrder(Tree root) {
if (!(root.isEmpty())) {
visit(root);
for (Iterator localIterator = root.getChilds().iterator(); localIterator.hasNext(); ) {
Tree child = (Tree) localIterator.next();
if (child == null)
break;
preOrder(child);
}
}
}
public void postOrder(Tree root) {
if (!(root.isEmpty())) {
for (Iterator localIterator = root.getChilds().iterator(); localIterator.hasNext(); ) {
Tree child = (Tree) localIterator.next();
if (child == null)
break;
preOrder(child);
}
visit(root);
}
}
public void visit(Tree tree) {
System.out.print("\t" + tree.getRootData());
}
}