//down-up approach for normal BTree(not a BST) //there's no parent pointer Node *LCA(Node *pRoot, Node *p, Node *q) { if (!pRoot) return NULL; if (pRoot == p || pRoot == q) return pRoot; Node *L = LCA(pRoot->pLeft, p, q); Node *R = LCA(pRoot->pRight, p, q); if (L && R) return pRoot; return L ? L : R; }
EOF