Advertisement
Neveles

Untitled

Mar 15th, 2020
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1.     int getHeightSubTree(Node* node)
  2.     {
  3.         if (node == nullptr)
  4.         {
  5.             return 0;
  6.         }
  7.         int left, right;
  8.         if (node->left_ != nullptr)
  9.         {
  10.             left = getHeightSubTree(node->left_);
  11.         }
  12.         else
  13.         {
  14.             left = -1;
  15.         }
  16.         if (node->right_ != nullptr)
  17.         {
  18.             right = getHeightSubTree(node->right_);
  19.         }
  20.         else
  21.         {
  22.             right = -1;
  23.         }
  24.         int max = left > right ? left : right;
  25.         return max + 1;
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement