-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTreeTraversals.java
More file actions
47 lines (38 loc) · 857 Bytes
/
Copy pathTreeTraversals.java
File metadata and controls
47 lines (38 loc) · 857 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
37
38
39
40
41
42
43
44
45
46
47
class Node {
int key;
Node left, right;
public Node(int item) {
key = item;
left = right = null;
}
}
class BinaryTree {
Node root;
BinaryTree() {
root = null;
}
void printPostorder(Node node) {
if (node == null) {
return;
}
printPostorder(node.left);
printPostorder(node.right);
System.out.print(node.key + " ");
}
void printInorder(Node node) {
if (node == null) {
return;
}
printInorder(node.left);
System.out.print(node.key + " ");
printInorder(node.right);
}
void printPreorder(Node node) {
if (node == null) {
return;
}
System.out.print(node.key + " ");
printPreorder(node.left);
printPreorder(node.right);
}
}