| |

VerySource

 Forgot password?
 Register
Search
View: 1030|Reply: 3

Subroutine recursion

[Copy link]

2

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-2-16 23:00:01
| Show all posts |Read mode
Do you need to consider the size of the stack when recursive subroutine calls? Such as
power (x, n)
If N = 10, then 20 parameters are on the stack. If N = 1000 or more, isn't the stack going to explode!
Reply

Use magic Report

2

Threads

18

Posts

15.00

Credits

Newbie

Rank: 1

Credits
15.00

 China

Post time: 2020-4-19 21:30:01
| Show all posts
To consider the size of the stack, too small stack will overflow.
Reply

Use magic Report

0

Threads

23

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-4-27 21:45:01
| Show all posts
Not only to consider the parameters, but also the return address of the subroutine also needs to occupy the stack. In addition, there may be local variables in the subroutine that will also occupy the stack. So, sometimes non-recursive methods
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-27 22:30:01
| Show all posts
Or you can use functional languages ​​such as scheme, generally do not have to consider stack overflow
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