Question
Tower of Hanoi is a simple game which is usually used to demonstrate the use of recursion in algorithms. In this project, we will not
Tower of Hanoi is a simple game which is usually used to demonstrate the use of recursion in algorithms. In this project, we will not use recursion. We are going to solve the game using stacks and queues.
The objective of the game is to move the stack of disks (as shown in Figure-a) to a rod on the extreme right (as shown in Figure-b) following the below mentioned rules:
- Only one disk can be moved at a time
- A disk cannot be placed over a smaller disk
Implementation using Stack:
Develop a class StackTower to implement Tower of Hanoi
- You will have to create three stack objects representing the rods
- You need to push the three disk objects onto the rods
- Then you will pop from one rod and push it onto another rod
- Repeat this process while making sure that you are not placing a disk over a smaller one
Your program should print out the contents of the stack at the beginning. After each move print out the contents of all the 3 stacks until the final step where the third rod is populated with all the three disks. Show the simulation of solving Tower of Hanoi.
Important: The question asks us to use Python and iterative function and stack as a linked list. I understand the gist of the pseudo code but I cant seem to make it work!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started