| |

VerySource

 Forgot password?
 Register
Search
View: 9|Reply: 2

anxious! How do you write a recursive algorithm for calculating the height of a given binary tree?

[Copy link]

1

Threads

1

Posts

2

Credits

Newbie

Rank: 1

Credits
2

 China

Post time: 2020-3-4 09:30:01
| Show all posts |Read mode
BTnode is defined as follows:
Typedef struct BTnode {
          TeleType data;
     struct Btnode * rchild, * lchild;}

Main program definition:
Int Deepth (BTnode * t)
Recursive program recommendations:
Int subth (BTNode * t)
Reply

Use magic Report

0

Threads

9

Posts

6

Credits

Newbie

Rank: 1

Credits
6

 China

Post time: 2020-5-21 09:30:01
| Show all posts
Int subth (BTNode * t)
{
  int l, r;
  if (! t)
    return 0;
  l = subth (t-> left);
  r = subth (t-> right);
  if (l <r)
    return r + 1;
  else
    return l + 1;
}
Reply

Use magic Report

0

Threads

9

Posts

5

Credits

Newbie

Rank: 1

Credits
5

 China

Post time: 4 day(s) ago
| Show all posts
Positive solution upstairs!
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list