Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
357 B
2
Indexable
Never
TreeNode<int> *LCAinaBST(TreeNode<int> *root, TreeNode<int> *P, TreeNode<int> *Q)//hca wouldve been hard
{
    while(root!=NULL){
    if(root->data > P->data && root->data > Q->data) {
        root=root->left;
    }else if(root->data < P->data && root->data < Q->data) {
        root=root->right;
    }else{
    return root;  
    }
    }
}