please remove the problem from my code why im not getting ans
#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++;
}
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(q.front()->left==NULL){
q.front()->left=a;
count++;
}
else if(q.front()->right==NULL){
q.front()->right=a;
q.pop();
}
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;
root=insertvalue(root,y,q,count);
}
rightview(root,0);
return 0;
}