Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. void findHeight(node *n){
  2. if (n != NULL){
  3. findHeight(n->left);
  4. findHeight(n->right);
  5. if (n->left == NULL&&n->right == NULL){
  6. n->height = 0;
  7. n->maxSemipath = 0;
  8. }
  9. else if (n->left == NULL){
  10. n->height = n->right->height + 1;
  11. n->maxSemipath = n->height;
  12. }
  13. else if (n->right == NULL){
  14. n->height = n->left->height + 1;
  15. n->maxSemipath = n->height;
  16. }
  17. else{
  18. int a = n->right->height;
  19. int b = n->left->height;
  20. n->height = a > b ? a + 1 : b + 1;
  21. n->maxSemipath = a+b+2;
  22. }
  23. if (n->maxSemipath > maxSemipath)
  24. maxSemipath = n->maxSemipath;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement