Tree right view

mr right view fn is doing right but i think im getting prblm in my insert fn please debug that
#include
#include
using namespace std;
int k=-1;
class node{
public:
int data;
node* left;
node* right;
node(int d){
data=d;
left=NULL;
right=NULL;
}

};

void rightview(node *root,int n){
if(root==NULL){
return ;
}
if(n>k){
cout<data<<" ";
k=n;
}
rightview(root->right,n+1);

rightview(root->left,n+1);

}

node* insertvalue(node root,int value,queue<node> &q, int &count ){
node *a;
if(value==-1){
a=new node(value);}
else{
a=NULL;
}

if(count==0){
q.front()->left=a;
count++;
}
else{
q.front()->right=a;

q.pop();
count=0;

}

if(value!=-1){
q.push(a);
}
return root;

}

int main() {

queue<node*> q;
int x;
cin>>x;

node* root=new node(x);
q.push(root);
int count =0;
while(!q.empty()){
int y;
cin>>y;

insertvalue(root,y,q,count);

}

rightview(root,0);

return 0;

}

@deepakjumani09 hey apka build logic sahi nhi hai ,right view ka sahi hai ,level wise input leni hai ,see this input function:

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.