求树的深度
树的深度=max(左子树深度,右子树深度)+1
struct Node{int data;Node* leftchild;Node* rightchild;
};int deep(Node* t){if (t==NULL) return 0;int l=deep(t->leftchild);int r=deep(t->rightchild);return max(l,r)+1;
}
求最近公共祖先LCA
树的深度=max(左子树深度,右子树深度)+1
struct Node{int data;Node* leftchild;Node* rightchild;
};int deep(Node* t){if (t==NULL) return 0;int l=deep(t->leftchild);int r=deep(t->rightchild);return max(l,r)+1;
}