can anyone help me with this code? I cannot figure out where I'm blocked.

Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.

```
TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {
   TreeNode* res=NULL;
   int i=0;
   postTrav(root,p,q,res,i);
   return res;
}

void postTrav(TreeNode* root, TreeNode* p, TreeNode* q,TreeNode* res,int& i){

    if(!root){
        return;
    }
    postTrav(root->left,p,q,res,i);
    postTrav(root->right,p,q,res,i);
    if(root==p||root==q){
        i++;
    }
    if(i==2){
        res=root;
        i++;
    }
}

```