Pair sum in BST,please check whats wrong in my code

#include<bits/stdc++.h>
using namespace std;
class node{
public:
int data;
node* left;
node* right;
node(int d)
{
data=d;
left=NULL;
right=NULL;
}
};
vector<vector> v;
node* build(int a,int s,int e)
{
if(s>e)
return NULL;
int mid=(s+e)/2;
node
root=new node(a[mid]);
root->left=build(a,s,mid-1);
root->right=build(a,mid+1,e);
return root;

}
void print(node* root)
{
if(root==NULL)
return;
print(root->left);
cout<data<<" ";
print(root->right);
return;

}
void treetolist(node* root,node *head)
{
if(root==NULL)
return;
static node
prev=NULL;
treetolist(root->left,head);
if(prev==NULL)
head=root;
else{
root->left=prev;
prev->right=root;
}
prev=root;
treetolist(root->right,head);
}
void printlist(node
root)
{
if(root==NULL)
return;
while(root!=NULL)
{
cout<data<<" ->";
root=root->right;

}

}
void getpair(node* head,int k)
{
if(head==NULL)
return;
node* c=head;
while(c->right!=NULL)
{
c=c->right;
}
node* p=head;
int s=0;
while(p!=NULL)
{
s++;
p=p->right;
}
int mid=s/2;

node* d=head;



for(int i=0;i<mid+1;i++)
{
    if(c->data + d->data== k)
    {
        cout<<c->data<<" "<<d->data<<endl;
        c=c->left;
        d=d->right;
        
    }
    if(c->data + d->data > k)
    {
    c=c->left;
    }
    if(c->data + d->data < k)
    {
        d=d->right;
    }
}

}

int main() {int n;
cin>>n;
int a[1005];
for(int i=0;i<n;i++)
{
cin>>a[i];

}
int k;
cin>>k;
node* p=build(a,0,n-1);

node* head=NULL;
treetolist(p,&head);
getpair(head,k);

return 0;

}

Provide the Qn. link as well

Yes,please provide the question link and try to save your code in online coding block IDE and then gave its link hereā€¦