import
java.util.*;
class
GFG{
static
class
node
{
char
val;
node left;
node right;
};
static
node newnode(
char
i)
{
node temp =
null
;
temp =
new
node();
temp.val = i;
temp.left =
null
;
temp.right =
null
;
return
temp;
}
static
node conv_tree(node root,
node shoot)
{
if
(root.left !=
null
)
shoot = conv_tree(root.left,
shoot);
root.left = shoot;
if
(shoot !=
null
)
shoot.right = root;
shoot = root;
if
(root.right !=
null
)
shoot = conv_tree(root.right,
shoot);
return
shoot;
}
static
int
checkPalin(node root)
{
node voot = root;
int
j =
0
;
while
(voot.left !=
null
)
{
j = j +
1
;
voot = voot.left;
}
int
i =
0
;
while
(i < j)
{
if
(voot.val != root.val)
return
0
;
else
{
i = i +
1
;
j = j -
1
;
voot = voot.right;
root = root.left;
}
}
return
1
;
}
public
static
void
main(String[] args)
{
node root = newnode(
'b'
);
root.left = newnode(
'b'
);
root.right = newnode(
'a'
);
root.left.right = newnode(
'b'
);
root.left.left = newnode(
'a'
);
node shoot = conv_tree(root,
null
);
if
(checkPalin(shoot) ==
1
)
System.out.print(
"True"
+
"\n"
);
else
System.out.print(
"False"
+
"\n"
);
}
}