Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void findHeight(node *n){
- if (n != NULL){
- findHeight(n->left);
- findHeight(n->right);
- if (n->left == NULL&&n->right == NULL){
- n->height = 0;
- n->maxSemipath = 0;
- }
- else if (n->left == NULL){
- n->height = n->right->height + 1;
- n->maxSemipath = n->height;
- }
- else if (n->right == NULL){
- n->height = n->left->height + 1;
- n->maxSemipath = n->height;
- }
- else{
- int a = n->right->height;
- int b = n->left->height;
- n->height = a > b ? a + 1 : b + 1;
- n->maxSemipath = a+b+2;
- }
- if (n->maxSemipath > maxSemipath)
- maxSemipath = n->maxSemipath;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement