Verticle order traversal using hashmap segmentation error

level order traversal is wright but vop is wrong
#include
#include
#include
#include <bits/stdc++.h>
using namespace std;
struct node{
node *left;
int data;
node right;
};
node
buildtree(node root){
int d;
cin>>d;
if(root==NULL){
root =new node;
root->data=d;
root->left=NULL;
root->right=NULL;
}
queue<node
> p;
p.push(root);
while(!p.empty()){
node *f=p.front();
p.pop();
int c1,c2;
cin>>c1>>c2;
if(c1!=-1){
node *r= new node;
r->data=c1;
r->left=NULL;
r->right=NULL;
f->left=r;
p.push®;
}
if(c2!=-1){
node *r1=new node;
r1->data=c2;
r1->left=NULL;
r1->right=NULL;
f->right=r1;
p.push(r1);
}
}

return root;
}

void printPreorder(node* node)
{
if (node == NULL)
return;

/* first print data of node */
cout << node->data << " "; 

/* then recur on left sutree */
printPreorder(node->left);  

/* now recur on right subtree */
printPreorder(node->right); 

}
void vop(node* root,int d,map<int,vector>&m){
m[d].push_back(root->data);
vop(root->left,d-1,m);
vop(root->left,d+1,m);
}

int main(){
int n;
cin>>n;
struct node *root=NULL;
root=buildtree(root);

map<int,vector>m;
int d=0;
vop(root,d,m);
for(auto it=m.begin();it!=m.end();it++)
{
// cout<first<<" ";

    for(int j=0;j<it->second.size();j++)
      {
          cout<<it->second[j]<<" ";
      }
      cout<<endl;
}

}

@dineshjani please provide the code in Coding Blocks IDE.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.