File tree Expand file tree Collapse file tree 1 file changed +74
-0
lines changed Expand file tree Collapse file tree 1 file changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class aufbauPrint
2
+ {
3
+ class Node
4
+ {
5
+ int data ;
6
+ Node right ,left ;
7
+ Node (int data )
8
+ {
9
+ this .data = data ;
10
+ right = left = null ;
11
+ }
12
+ }
13
+ Node root ;
14
+ void insert (int data )
15
+ {
16
+ //System.out.println("*");
17
+ root = insertdata (root ,data );
18
+ }
19
+ Node insertdata ( Node root ,int data )
20
+ {
21
+ if (root == null )
22
+ {
23
+ //System.out.println("*");
24
+ root = new Node (data );
25
+ return root ;
26
+ }
27
+ if (data < root .data )
28
+ {
29
+ root .left = insertdata (root .left ,data );
30
+ //System.out.println("*");
31
+ }
32
+ else
33
+ {
34
+ root .right = insertdata (root .right , data );
35
+ //System.out.println("*");
36
+ }
37
+ return root ;
38
+ }
39
+ void display ()
40
+ {
41
+ print (root );
42
+ }
43
+ void print (Node root )
44
+ {
45
+ if (root == null )
46
+ {
47
+ return ;
48
+ }
49
+ System .out .print (root .data + " " );
50
+ print (root .left );
51
+ print (root .right );
52
+ }
53
+ public static void main (String []args )
54
+ {
55
+
56
+ aufbauPrint tree = new aufbauPrint ();
57
+ tree .insert (40 );
58
+ tree .insert (30 );
59
+ tree .insert (20 );
60
+ tree .insert (35 );
61
+ tree .insert (70 );
62
+ tree .insert (50 );
63
+ tree .insert (21 );
64
+ tree .insert (10 );
65
+ tree .insert (36 );
66
+ tree .insert (32 );
67
+ tree .insert (55 );
68
+ tree .insert (60 );
69
+ tree .insert (82 );
70
+ tree .insert (76 );
71
+ tree .display ();
72
+
73
+ }
74
+ }
You can’t perform that action at this time.
0 commit comments