#include
using namespace std;
class node{
public:
int data;
node *left;
node *right;
node(int d)
{
data=d;
left=NULL;
right=NULL;
}
};
node *builtTree()
{
int d;
cin>>d;
if(d==-1)
{
return NULL;
}
node *root=new node(d);
root->left = builtTree();
root->right = builtTree();
return root;
}
void preorder(node *root)
{
if(root==NULL)
{
return;
}
cout<data<<" “;
preorder(root->left);
preorder(root->right);
}
void printrightView(node *root,int level,int &maxlevel)
{
if(root==NULL)
{
return ;
}
if(maxlevel<level)
{
cout<data<<” ";
maxlevel=level;
}
printrightView(root->right,level+1,maxlevel);
printrightView(root->left,level+1,maxlevel);
}
int main()
{
node *root=builtTree();
// preorder(root);
// cout<<endl;
int maxlevel=-1;
printrightView(root,0,maxlevel);
}