#include
#include
#include
using namespace std;
struct node{
int data;
node* left;
node* right;
};
int sum=0;
node* buildbst(node *root){
int d;
cin>>d;
if(root==NULL){
root =new node;
root->data=d;
root->left=NULL;
root->right=NULL;
}
string str1,str2;
cin>>str1;
if(str1==“true”){
root->left=buildbst(root->left);
cin>>str2;
if(str2==“true”){
root->right=buildbst(root->right);
}
else{
root->left=NULL;
root->right=NULL;
}
}
else{
cin>>str2;
if(str2==“true”){
root->right=buildbst(root->right);
}
else{
root->left=NULL;
root->right=NULL;
}
}
return root;
}
void zigzag(node root){
stack<node>s1;
stack<node*>s2;
s1.push(root);
while(s1.size()||s2.size()){
while(s1.size()){
node *w=s1.top();
cout<<w->data<<" ";
s1.pop();
if(w->left){
s2.push(w->left);}
if(w->right){
s2.push(w->right);}
}
while(s2.size()){
node *s=s2.top();
cout<<s->data<<" ";
s2.pop();
if(s->right){
s1.push(s->right);}
if(s->left){
s1.push(s->left);}
}
}
}
int main() {
node* root=NULL;
root= buildbst(root);
zigzag(root);
return 0;
}