Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

To get mirror image of a binary tree

Go down

 To get mirror image of a binary tree Empty To get mirror image of a binary tree

Post  Admin Wed Aug 24, 2011 12:23 pm

pubic static void getmirror(TreeNode root){
if(root==null)
return;
TreeNode temp=root.right;
root.right=root.left;
root.left=temp;
getmirror(root.left);
getmirror(root.right;)
}

Admin
Admin

Posts : 131
Join date : 2011-08-16

https://codefornongeek.forumotion.com

Back to top Go down

 To get mirror image of a binary tree Empty Giving two Binary Tree, judeg whether they are mirror?

Post  Admin Tue Aug 30, 2011 10:48 am

public static boolean judgeMirror(TreeNode n1, TreeNode n2){
if(n1!=n2)
return false;
if(n1==null&&n2==null)
return true;
judgeMirror(n1.left,n2.right);
judgeMirror(n1.right,n2.left);
return true;
}

Admin
Admin

Posts : 131
Join date : 2011-08-16

https://codefornongeek.forumotion.com

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum