#include<iostream>
#include<queue>
using namespace std;

class node
{
    int data;
    int no_of_children;
    node* left;
    node* right;

public:
    void set_data(int a)
    {
            data=a;
    }

    int get_data()
    {
        return data;
    }

    void set_left_node(node* anode)
    {
        left=anode;
    }

    void set_right_node(node* anode)
    {
        right=anode;
    }

    node* get_left_node()
    {
        return left;
    }

    node* get_right_node()
    {
        return right;
    }

    void set_no_of_children(int a)
    {
        if(a<0 || a>2)
            return;

        no_of_children=a;
    }

    int get_no_of_children()
    {
        return no_of_children;
    }
};

class tree
{
    node* root;

    public:
        void construct_tree()
        {
            queue <node*>q;
            root=new node;
            q.push(root);
            int d;
            cout<<"Enter the data of the root node: ";
            cin>>d;
            (q.front())->set_data(d);

            while(!q.empty())
            {
                int no_of_children;
                cout<<"Enter the number of children of "<<q.front()->get_data()<<": ";
                cin>>no_of_children;
                q.front()->set_no_of_children(no_of_children);

                for(int i=0;i<(q.front()->get_no_of_children());i++)
                {
                    node* temp=new node;
                    if(i==0)
                    {
                        int lc;
                        cout<<"Enter the left child of: "<<q.front()->get_data()<<": ";
                        cin>>lc;
                        temp->set_data(lc);
                        q.front()->set_left_node(temp);
                        q.push(temp);
                    }
                    else if(i==1)
                    {
                        int rc;
                        cout<<"Enter the right child of: "<<q.front()->get_data()<<": ";
                        cin>>rc;
                        temp->set_data(rc);
                        q.front()->set_right_node(temp);
                        q.push(temp);
                    }
                }

                if(q.front()->get_no_of_children()==0)
                {
                    q.front()->set_left_node(0);
                    q.front()->set_right_node(0);
                }

                q.pop();
            }

        }

        void in_order_print()
        {
            
        }
};

int main()
{
    tree t;
    t.construct_tree();
    t.in_order_print();
}
