To get mirror image of a binary tree

View previous topic View next topic Go down

To get mirror image of a binary tree

Post  Admin on 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

View user profile http://codefornongeek.forumotion.com

Back to top Go down

Giving two Binary Tree, judeg whether they are mirror?

Post  Admin on 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

View user profile http://codefornongeek.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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