File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Node
2
+ {
3
+ int data ;
4
+ Node left ;
5
+ Node right ;
6
+ Node (int data )
7
+ {
8
+ this .data =data ;
9
+ left =right =null ;
10
+ }
11
+ }
12
+
13
+ class BinaryTree {
14
+ Node root ;
15
+ BinaryTree ()
16
+ {
17
+ root = null ;
18
+ }
19
+ BinaryTree (int data )
20
+ {
21
+ this .root =new Node (data );
22
+ }
23
+ Node mirror (Node root )
24
+ {
25
+ if (root ==null )
26
+ {
27
+ return null ;
28
+ }
29
+ Node temp =root .left ;
30
+ root .left =root .right ;
31
+ root .right =temp ;
32
+ mirror (root .left );
33
+ mirror (root .right );
34
+ return root ;
35
+ }
36
+ }
37
+
38
+ class mirrorConvert {
39
+ public static void main (String [] args ) {
40
+
41
+ BinaryTree bt =new BinaryTree (2 );
42
+ bt .root .left =new Node (3 );
43
+ bt .root .right =new Node (5 );
44
+ bt .root .left .right =new Node (9 );
45
+ bt .root .right .left =new Node (7 );
46
+ Node temp =bt .mirror (bt .root );
47
+ System .out .println (temp .data +" " +temp .left .data +" " +temp .right .data );
48
+
49
+ }
50
+ }
You can’t perform that action at this time.
0 commit comments