#include
#include
using namespace std;
class node
{
public:
int data;
node *left;
node *right;
node(int d)
{
data=d;
left=NULL;
right=NULL;
}
};
node * buildTree()
{
int d;
cin>>d;
if(d==-1)
return NULL;
node *root=new node(d);
root->left=buildTree();
root->right=buildTree();
return root;
}
void bfs(node *root)
{
queue<node *> q;
cout<data<<endl;;
q.push(root);
while(!q.empty())
{
node *p=q.front();
q.pop();
if(p->left!=NULL)
{
cout<left->data<<" “;
q.push(p->left);
}
if(p->right!=NULL)
{
cout<right->data<<” ";
q.push(p->right);
}
if(p->left && p->right)
cout<<endl;
}
return;
}
int main()
{
node *root=buildTree();
bfs(root);
}