| |

VerySource

 Forgot password?
 Register
Search
View: 930|Reply: 4

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

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 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

10

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 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.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-3 13:45:01
| Show all posts
Positive solution upstairs!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-17 00:45:01
| Show all posts
How come there is no separation between the main program and the recursive function program?
Reply

Use magic Report

0

Threads

22

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-7-20 10:00:01
| Show all posts
This is to ask the original poster what is "recursive program suggestion:...", typedef has never seen such
Work around:
Int Deepth(BTnode *t){
  return subth(t);
}
^_^
Reply

Use magic Report

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

Points Rules

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

Quick Reply To Top Return to the list