Advertisement
Guest User

height

a guest
Mar 28th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. int  Tree_height(Node* node)
  2. {
  3.     Node *htemp = node;
  4.     int lcounter = 1;
  5.     int rcounter = 1;
  6.    
  7.     if (node == NULL)
  8.     {
  9.         return 0;
  10.     }
  11.  
  12.     if (htemp->left !=  NULL)
  13.     {
  14.         lcounter += Tree_height(htemp->left);
  15.     }
  16.     if (htemp->right != NULL)
  17.     {
  18.         rcounter += Tree_height(htemp->right);
  19.     }
  20.     if (lcounter >= rcounter)
  21.     {
  22.         return lcounter;
  23.     }
  24.     else
  25.     {
  26.         return rcounter;
  27.     }
  28.    
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement