| |

VerySource

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

Subroutine recursion

[Copy link]

2

Threads

3

Posts

4

Credits

Newbie

Rank: 1

Credits
4

 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

Credits

Newbie

Rank: 1

Credits
15

 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

22

Posts

16

Credits

Newbie

Rank: 1

Credits
16

 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

Credits

Newbie

Rank: 1

Credits
2

 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-2020|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list