#include<iostream>
#include<fstream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<string>
#include <iomanip>
using namespace std;
struct node
{
int value;
node *left,*right;
node(){value=0;left=right=NULL;}
};
int itemp=0;
string stemp;
int NUM=0;
int N;
node * maketree();
void printtree(node* tree);
//#define fin cin
int main()
{
/*ifstream fin("d:\in.txt" );
if (! fin.is_open())
{
cout << "Error opening file";
system("pause");
exit (1);
}*/
cin>>N;
cin>>stemp;
if(stemp=="Push")
{
cin>>itemp;
}
node *tree;
tree=maketree();
NUM=0;
printtree(tree);
system("PAUSE");
return 0;
}
node * maketree()
{
if(stemp=="Push")
{
node *ntemp=new node;
NUM++;
ntemp->value=itemp;
cin>>stemp;
if(NUM==N)
{
return ntemp;
}
if(stemp=="Push")
{
cin>>itemp;
}
if(stemp=="Push")
{
ntemp->left=maketree();
}
if(NUM==N)
{
return ntemp;
}
cin>>stemp;
if(stemp=="Push")
{
cin>>itemp;
}
if(stemp=="Push")
{
ntemp->right=maketree();
}
return ntemp;
}
else
{
return NULL;
}
}
void printtree(node* tree)
{
if(tree)
{
printtree(tree->left);
printtree(tree->right);
if(NUM==0)
cout<<tree->value;
else
cout<<" "<<tree->value;
NUM=1;
}
}
#include<fstream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<math.h>
#include<string>
#include <iomanip>
using namespace std;
struct node
{
int value;
node *left,*right;
node(){value=0;left=right=NULL;}
};
int itemp=0;
string stemp;
int NUM=0;
int N;
node * maketree();
void printtree(node* tree);
//#define fin cin
int main()
{
/*ifstream fin("d:\in.txt" );
if (! fin.is_open())
{
cout << "Error opening file";
system("pause");
exit (1);
}*/
cin>>N;
cin>>stemp;
if(stemp=="Push")
{
cin>>itemp;
}
node *tree;
tree=maketree();
NUM=0;
printtree(tree);
system("PAUSE");
return 0;
}
node * maketree()
{
if(stemp=="Push")
{
node *ntemp=new node;
NUM++;
ntemp->value=itemp;
cin>>stemp;
if(NUM==N)
{
return ntemp;
}
if(stemp=="Push")
{
cin>>itemp;
}
if(stemp=="Push")
{
ntemp->left=maketree();
}
if(NUM==N)
{
return ntemp;
}
cin>>stemp;
if(stemp=="Push")
{
cin>>itemp;
}
if(stemp=="Push")
{
ntemp->right=maketree();
}
return ntemp;
}
else
{
return NULL;
}
}
void printtree(node* tree)
{
if(tree)
{
printtree(tree->left);
printtree(tree->right);
if(NUM==0)
cout<<tree->value;
else
cout<<" "<<tree->value;
NUM=1;
}
}