How to take the -1 input

i want to make the -1 input to NULL so that it doesn’t make create its left and right pointer and leave it for the next consecutive node

eg = 1,2,3,4,5,-1,-1,6,7,8,9,10,11

it should make the tree like this-
1
/ \
2 3
/ \ /
4 5 n n
/ \ /
6 7 8 9
/
10 11

but it is making it like this -

                                  1
                            /        \ 
                           2           3
                        / \          / \
                       4    5        n   n
                    /  \  / \      /\
                  6    7  8   9   10 11

your method of of building tree is wrong

you have to use level order traversal way to take input

use this function to take build tree

node* buildTree(){
		queue<node*>q;
		int d;cin>>d;
		node* root=new node(d);
		q.push(root);
		while(!q.empty()){
			node*temp=q.front();
			q.pop();
			int rc,lc;
			cin>>rc>>lc;
			if(rc!=-1){
				temp->left=new node(rc);
				q.push(temp->left);
			}
			if(lc!=-1){
				temp->right=new node(lc);
				q.push(temp->right);
			}

		}
		return root;
}

if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like :heart:: and don’t forgot to mark doubt as resolved :grinning: