Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/floressek/hanoi_tower
Some coding for Data Structures and Algorythms
https://github.com/floressek/hanoi_tower
data-structures hanoi-towers
Last synced: 7 days ago
JSON representation
Some coding for Data Structures and Algorythms
- Host: GitHub
- URL: https://github.com/floressek/hanoi_tower
- Owner: Floressek
- License: mit
- Created: 2024-02-29T21:07:16.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-04-08T22:59:39.000Z (7 months ago)
- Last Synced: 2024-10-10T11:25:20.769Z (28 days ago)
- Topics: data-structures, hanoi-towers
- Language: C++
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tower of Hanoi
This is a C++ implementation of the classic Tower of Hanoi problem. The program takes in the number of disks to be moved and solves the problem using recursive moves.
## Functionality
* `createStack()`: Creates a new stack with the given size.
* `isFull()`: Returns true if the stack is full, false otherwise.
* `isEmpty()`: Returns true if the stack is empty, false otherwise.
* `push()`: Pushes an item onto the stack.
* `pop()`: Removes and returns the top item from the stack.
* `moveDisk()`: Moves a disk from one peg to another.
* `solveTowerOfHanoi()`: Solves the Tower of Hanoi problem using recursive moves.
* `printStacks()`: Prints the current state of the stacks.## Implementation
The program uses three stacks: `source`, `auxiliary`, and `destination`. The `solveTowerOfHanoi()` function takes in the number of disks to be moved, the `source` stack, the `auxiliary` stack, and the `destination` stack. It then solves the problem using recursive moves, printing the current state of the stacks at each step.
The `moveDisk()` function moves a disk from one peg to another. The `printStacks()` function prints the current state of the stacks, with the disks represented as integers on the pegs.
## Testing
To test this program, simply run it and enter the number of disks to be moved. The program will then solve the problem and print the current state of the stacks at each step.
Note: This program only supports moving up to a maximum of 8 disks.