#include<bits/stdc++.h>
using namespace std;
class node{
public:
int data;
node* left;
node* right;
node(int d){
data=d;
left=NULL;
right=NULL;
}
};
void create(node* &root){
int d;
cin>>d;
root=new node(d);
string left,right;
cin>>left;
if(left=="true"){
//cin>>d;
//root->left=new node(d);
create(root->left);
}
cin>>right;
if(right=="true"){
//cin>>d;
//root->right=new node(d);
create(root->right);
}
}
class HBpair{
public:
int height;
bool balance;
};
HBpair heightbst(node* root){
HBpair p;
if(root==NULL){
p.height=0;
p.balance =true;
}
HBpair left=heightbst(root->left);
HBpair right=heightbst(root->right);
p.height=max(left.height,right.height)+1;
if(abs(left.height -right.height)<=1 && left.balance && right.balance){
p.balance=true;
}
else{
p.balance=false;
}
return p;
}
int main(){
node* root=NULL;
create(root);
if(heightbst(root).balance){
cout<<“true”;
}
else{
cout<<"false";
}
return 0;
}
why it shows segmentation fault