-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoundaryTraversal.java
More file actions
51 lines (44 loc) · 1.16 KB
/
BoundaryTraversal.java
File metadata and controls
51 lines (44 loc) · 1.16 KB
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
48
49
50
import java.util.ArrayList;
public class BoundaryTraversal {
class Node {
int data;
Node left, right;
Node(int data) {
this.data = data;
this.left = null;
this.right = null;
}
}
static ArrayList<Integer> al;
public static void printLeft(Node root) {
if(root == null) return ;
al.add(root.data);
if(root.left != null) {
printLeft(root.left);
}
else if(root.right != null) {
printLeft(root.right);
}
}
public static void printRight(Node root) {
if(root == null) return ;
al.add(root.data);
if(root.right != null) {
printRight(root.right);
}
else if(root.left != null) {
printRight(root.left);
}
}
public static void printLeaves(Node root) {
if (root == null) return;
if(root.left == null && root.right == null) al.add(root.data);
printLeaves(root.left);
printLeaves(root.right);
}
public static void main(String args[]) {
al = new ArrayList<>();
//if ()
//al.add()
}
}