You can get a solution to the Towers of Hanoi problem by using the following iterative algorithm. Beginning with pole 1 and moving from pole to pole in the order pole 1, pole 3, pole 2, pole 1, and so on, make at most one move per pole according to the following rules:
• Move the topmost disk from a pole to the next possible pole in the specified order. Remember that you cannot place a disk on top of a smaller one.
• If the disk that you are about to move is the smallest of all the disks and you just moved it to the present pole, do not move it. Instead, consider the next pole.
This algorithm should make the same moves as the recursive algorithms given in Segment 7.31 and pictured in Figure 1. Thus, this iterative algorithm is O(2n) as well.
Implement this algorithm.
FIGURE 1 The sequence of moves for solving the Towers of Hanoi problem with three disks

We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.