Answer

By using the function, you could solve the entire stack from the ground up. Look at the rod stack diagram again. You already know the positions of the rods at the bottom of the stack: rods 1, 2, and 3. Rod 4 is supported by rods 1 and 2. This means that you can answer the question:

``Where is the center of rod 4?''

by giving the necessary information about rods 1, 2, and 4 to the function. Similarly, rods 2 and 3 support rod 5. You can use answer the question:

``Where is the center of rod 5?''

by giving the necessary information to the function. By continuing in this way, you can use the function over and over to ``climb up'' the stack and determine the positions of all the rods.

Return to lesson.



Eric N. Eide
Hamlet Project
Department of Computer Science
University of Utah