Another way implimentation

how to solve this problem using iterative way

Do you want me to tell you the algo or approach to solve TOH in iterative way?

The iterative solution can be figured out analyzing the recursive solution. Two things worth notice are that:

  1. Total no. of moves required are 2n−12n−1 where n is the number of disks. This can be evaluated by the recurrence of the recursive solution.
  2. If the poles are arranged in space as:
    image
    then for the even number of disks the movement of disks will start in clockwise direction and if the number of disks is odd then the movement will start in anticlockwise direction.

The algo for the same can be this

TowerOfHanoi(source, destination, auxiliary, numDisks)

1. Calculate total no. of moves as pow(2, numDisks) - 1. numDisks is no. of disks. 

2. If numDisks is even then interchange the destination pole with the auxiliary pole. (This is to ensure that moves are in clockwise for even disks and anticlockwise for odd disks)

3. for i = 1 to number of moves calculate in step 1:

   a. if i%3 == 1:
      legal movement of top disk b/w source pole and destination pole.
   b. if i%3 == 2:
      legal movement of top disk b/w source pole and auxiliary pole.
   c. if i%3 == 0:
      legal movement of top disk b/w auxiliary pole and destination pole.

Also if you have any doubt left, please ask instead of reopening it. And if there are no doubts left, mark it as resolved