what does…
isHeightBalance(root).balance
mean…?
plzz the the use of dot operator here…
what does…
isHeightBalance(root).balance
mean…?
plzz the the use of dot operator here…
HBPair isHeightBalance(node *root){
HBPair p;
if(root==NULL){
p.height = 0;
p.balance = true;
return p;
}
//Recurisve Case
HBPair left = isHeightBalance(root->left);
HBPair right = isHeightBalance(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 = buildTree();
if(isHeightBalance(root).balance){
cout<<"Balanced";
}
else{
cout<<"Not a Balanced Tree"<<endl;
}
//in main…
isHeightBalance(root).balance)
hey @ynikhil1999, HBPair must be a class in code having 2 public members height and balance.
. operator is used to access the public members of class using object of class.
isHeightBalance(root) is function call that will return an object of type HBPair. Now using this object you are accessing balance data member with the statement isHeightBalance(root).balance