I am unable to understand the input format of checking is balanced. can u plzz help and can u give me the level order of this binary tree which we have input?
Is balanced binary tree
hi khushi
class node
{
public:
string data;
nodeleft;
noderight;
node(string d)
{
data=d;
left=NULL;
right=NULL;
}
};
nodebuildtree()
{
string str;
cin>>str;
if(str==“false”)
{
return NULL;
}
if(str==“true”)
{
string d;
cin>>d;
noderoot=new node(d);
root->left=buildtree();
root->right=buildtree();
return root;
}
node*root=new node(str);
root->left=buildtree();
root->right=buildtree();
return root;
}
this is the way in which you are suppossed to build the tree.
and then you can simply build a boolen function for checking if tree is balanced.