forked from joharbatta/DataStructure-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreorder.java
More file actions
50 lines (43 loc) · 946 Bytes
/
Copy pathpreorder.java
File metadata and controls
50 lines (43 loc) · 946 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
48
49
50
public class preorder
{
public Tnode root;
public class Tnode
{
public Tnode left;
public Tnode right;
public int data;
public Tnode(int data)
{
this.data=data;
}
}
public void createTree()
{
Tnode first=new Tnode(1);
Tnode second=new Tnode(2);
Tnode third=new Tnode(3);
Tnode fourth=new Tnode(4);
Tnode fifth=new Tnode(5);
root=first;
first.left=second;
first.right=third;
second.left=fourth;
second.right=fifth;
}
public void preOrder(Tnode root)
{
if(root==null)
{
return;
}
System.out.print(root.data+" ");
preOrder(root.left);
preOrder(root.right);
}
public static void main(String args[])
{
preorder b=new preorder();
b.createTree();
b.preOrder(b.root);
}
}