寻找完全二叉树的最近公共祖先问题

编译通过了但是代码没有输出

代码如下
#include
#include
using namespace std;

struct TreeNode{
    int x;
    TreeNode* left;
    TreeNode* right;
};

TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q){
    if(root==p||root==q||!root)return root;
       
    TreeNode* left=lowestCommonAncestor(root->left,p,q);
    TreeNode* right=lowestCommonAncestor(root->right,p,q);
       
    if(!left&&!right)return NULL;
    else if(left&&!right)return left;
    else if(right&&!left)return right;
       
    return root;
}

TreeNode* Search(TreeNode* &root,int i){
    if((root->x)==i){
        return root;
    }
    TreeNode* pNode=NULL;
    if(root->left!=NULL){
        pNode=Search(root->left,i);
        if(!pNode){
            return pNode;
        }
    }
    if(root->right!=NULL){
        pNode=Search(root->right,i);
        if(!pNode){
            return pNode;
        }
    }
    return NULL;
}

void CreateTree(TreeNode* &root,int a,int len,int loc)
{
    if(loc>=len){root=NULL;return;}
    root->x=a[loc];
    CreateTree(root->left,a,len,2
loc+1);
    CreateTree(root->right,a,len,2*(loc+1));
}

int main(){
    TreeNode* root=(TreeNode*)malloc(sizeof(TreeNode));
    int a[1000];
    for(int i=0;i<1000;i++){
        a[i]=i+1;
    }
    CreateTree(root,a,999,0);
    int m,n,Y;
    cin>>Y;
    for(int i=0;i<Y;i++){
        cin>>m>>n;
        TreeNode* p=Search(root,m);
        TreeNode* q=Search(root,n);
        TreeNode* r=lowestCommonAncestor(root,p,q);
        cout<x<<endl;
    }
}

求大神解答!

你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答


本次提问扣除的有问必答次数,已经为您补发到账户,我们后续会持续优化,扩大我们的服务范围,为您带来更好地服务。