go to previous page   go to home page   go to next page

Answer:

The last one on the chain.


Stack

Recursion is similar to a stack of work on a desk top. You can work only on the task on top of a stack, and can work on a task beneath it only when the top stack is finished.

But often as you work on the top task you discover that it requires you to do some sub-task, which now becomes the top of the stack. And that sub-task may itself require some sub-task, which an even newer top-of-stack.

The stack may grow and grow and tasks spawn sub-tasks, and then shrink as sub-tasks are completed. But sometimes a task requires several sub-tasks and each one may start another round of stack growth and shrinkage. Eventually (if all goes well) the original task is on the top of the stack and can be completed.

Stack of Tasks

QUESTION 9:

Could a recursive method add up the integers from one to 100 ?