Question: You are required to design an algorithm which solves the Tower of Hanoi puzzle (see the figure below). You have an array of stacks (use



You are required to design an algorithm which solves the Tower of Hanoi puzzle (see the figure below). You have an array of stacks (use the ListStack implementation) named rods with size 3 All three of the stacks are in the same size which is n. At the beginnin rods 0] (first stack) is full of discs marked with positive integers from 1 to n where i is at the top and n is at the bottom (i.e., you need three stacks of Integers with the first initialized to store the n Integers) The other two stacks are empty The goal of the puzzle: is to move all these disks from rods[0] to the third rod, rods12], with the help of rods[ij, without breaking any rules of the Tower of Hanoi puzzle. The rules of the game are: Only one disc may be moved at a time. Each move consists of taking the top (smallest disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod. No disk may be placed on top of a smaller disk. Hints: To move a stack of k discs from rod A to rod B, we first move k-1 discs from A to C, then move the remaining (kth) disc from rod A to B, and then finally move all k-1 discs on C to B. Also, if you closely examine the puzzle you will see that there is at most one legal move between any two rods
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
