Tree left view problem

why isn’t my code giving expected output?

#include
#include
using namespace std;

class node{

public:
int data;
node *left,*right;

node(int data)
{
	this->data = data;
	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 leftView(node *root,int level,int& max_level){
if(root == NULL)
return;

if (max_level<level){
	cout<<root->data<<" ";
	max_level = level;
}
leftView(root->left,level+1,max_level);
leftView(root->right,level+1,max_level);

}

int main(){
node* root = buildTree();
int max_level = -1;
leftView(root,0,max_level);
return 0;
}

hello @nimit_jain

pls save ur code here-> https://ide.codingblocks.com/
and share its link with me.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.