-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeftViewBinaryTree.java
More file actions
41 lines (39 loc) · 1.01 KB
/
LeftViewBinaryTree.java
File metadata and controls
41 lines (39 loc) · 1.01 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
package Ds.Achievers;
class Node1{
int data;
Node1 left;
Node1 right;
Node1(int temp){
data=temp;
left=right=null;
}
}
public class LeftViewBinaryTree {
static Node1 root;
static int levelMax=0;
public void leftView(){
leftView(root, 1);
}
public void leftView(Node1 temp, int level){
if (temp==null)
return;
if (levelMax<level){
System.out.print(temp.data+" ");
levelMax=level;
}
leftView(temp.left, level+1);
leftView(temp.right, level+1);
}
public static void main(String[] args) {
LeftViewBinaryTree tree=new LeftViewBinaryTree();
root=new Node1(10);
root.left=new Node1(20);
root.right=new Node1(30);
root.left.left=new Node1(40);
root.left.right=new Node1(50);
root.left.right.left=new Node1(70);
root.left.right.left.right=new Node1(80);
root.right.right=new Node1(60);
tree.leftView();
}
}