Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. struct odp{
  2.     int height;
  3.      bool ok;
  4. };
  5.  
  6. odp ifBST(BSTnode * root){
  7.     odp o;
  8.     o.ok=true;
  9.     if(root == NULL){
  10.         o.height=0;
  11.     }
  12.     else{
  13.         odp leftHeight = ifBST(root->left) , rightHeight = ifBST(root->right);
  14.         if(abs(leftHeight.height-rightHeight.height)>1){
  15.             o.ok=false;
  16.         }
  17.         o.height = 1 + max(leftHeight.height, rightHeight.height);
  18.     }
  19.     return o;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement