Mirror Image Of Tree
Code:
boolean areMirror(Node a, Node b)
{
/* Base case : Both empty */
if (a == null && b == null)
return true;
// If only one is empty
if (a == null || b == null)
return false;
return a.data == b.data
&& areMirror(a.left, b.right)
&& areMirror(a.right, b.left);
}
boolean areMirror(Node a, Node b)
{
/* Base case : Both empty */
if (a == null && b == null)
return true;
// If only one is empty
if (a == null || b == null)
return false;
return a.data == b.data
&& areMirror(a.left, b.right)
&& areMirror(a.right, b.left);
}
0 Comments:
Post a Comment