Sir will this code give right output when printing tree in level order where each level is in a new line

#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);

}

hi @Mukul-Shane-1247687648773500 please send the code in ide.codingblocks.com

hi @Mukul-Shane-1247687648773500 no this wont work as u need to print new line when one level is complete u are printing when it doesnt have and child
refer https://ide.codingblocks.com/s/666774
do a dry run on paper