Tuesday, November 29, 2011

Check if given two trees are identical to each other

   public static boolean isIdentical(BinaryTree root, BinaryTree root1){
     if(root1==null && root==null)
        return true;
     else if(root1!=null && root!=null){
      if(root1.value==root.value)
        return(isIdentical(root1.left,root.left) && isIdentical(root1.right,root.right));
      }
     return false;
     
   }

No comments:

Post a Comment