File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ *
3+ */
4+ package TREES ;
5+ import java .util .*;
6+
7+ /**
8+ * @author M.NAVEEN
9+ * RANDOM CODER'S
10+ * Tech/Project Lead Android Club
11+ */
12+ public class TressDemo
13+ {
14+ static Scanner nav =new Scanner (System .in );
15+
16+ static class node {
17+ node left ,right ;
18+ int data ;
19+
20+ node (int data ){this .data =data ;}
21+ }
22+ public static node createTree ()
23+ { node root =null ;
24+ System .out .println ("Enter the Data :" );
25+ int data =nav .nextInt ();
26+ if (data ==-1 ) {
27+ return null ;
28+ }
29+
30+ root =new node (data );
31+ System .out .println ("The data entered on Left :" +data );
32+ root .left =createTree ();
33+ System .out .println ("The data entered on Right :" +data );
34+ root .right =createTree ();
35+
36+
37+ return root ;
38+
39+ }
40+
41+ public static void inOrder (node root )
42+ {
43+ if (root ==null ) {return ;}
44+
45+ inOrder (root .left );
46+ System .out .print (root .data +" " );
47+ inOrder (root .right );
48+ }
49+
50+ public static void PerOrder (node root )
51+ {
52+ if (root ==null ) {return ;}
53+ System .out .print (root .data +" " );
54+ PerOrder (root .left );
55+
56+ PerOrder (root .right );
57+ }
58+
59+ public static void PostOrder (node root )
60+ {
61+ if (root ==null ) {return ;}
62+
63+ PostOrder (root .left );
64+
65+ PostOrder (root .right );
66+ System .out .print (root .data +" " );
67+ }
68+
69+ public static void main (String [] args )
70+ {
71+ System .out .println ("Tree" );
72+ node root =createTree ();
73+ System .out .println ("Inorder !!!!" );
74+ inOrder (root );
75+
76+ System .out .println ("\n Postorder !!!!" );
77+ PostOrder (root );
78+ System .out .println ("\n PreOrder !!!!" );
79+ PerOrder (root );
80+ }
81+
82+ }
83+
Original file line number Diff line number Diff line change 1+ /**
2+ *
3+ */
4+ /**
5+ * @author M.NAVEEN
6+ * RANDOM CODER'S
7+ * Tech/Project Lead Android Club
8+ */
9+ package TREES ;
You can’t perform that action at this time.
0 commit comments