Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.