(a) Write an algorithm, pseudo code and draw flow chart for following scenario:
The mission is to move all the disks to some another tower without violating the
sequence of arrangement. A few rules to be followed for doing this are as follows −
Only one disk can be moved among the towers at any given time.
Only the "top" disk can be removed.
No large disk can sit over a small disk.
START
Procedure Hanoi(disk, source, dest, aux):
IF disk == 1, THEN:
move disk from source to dest
ELSE Hanoi(disk - 1, source, aux, dest): // Step 1
move disk from source to dest // Step 2 Hanoi(disk - 1, aux, dest, source) // Step 3
END IF
END Procedure
STOP
Comments
Leave a comment