//查找树中有没有这个结点
public static Node search(Node root,int val){
if(root==null){
return null;
}
if(root.value==val){
return root;
}
//除了这两种可能之外,会一直去左子树找
Node left=search(root.left,val);
//如果Left为空就不能来到判断这一步,会一直调用上面的方法
if(left!=null){
return left;
}
Node right=search(root.right,val);
if(right!=null){
return right;
}
return null;
}
//两个树互为镜像
public boolean isMirror(TreeNode p,TreeNode q){
if(p==null && q==null){
return true;
}
if(p==null||q==null){
return false;
}
return p.value==q.value
&&isMirror(q.left,p.right)
&&isMirror(q.right,p.left);
}
//树中查找值
public boolean search2(Node root,int val){
if(root==null){
return false;
}
if(root.value==val){
return true;
}
boolean left=search2(root.left,val);
if(left){
return true;
}
boolean right=search2(root.right,val);
if(right){
return true;
}
return false;
}