-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added stack labels to output
- Loading branch information
Showing
4 changed files
with
52 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <vector> | ||
#include <stack> | ||
#include <unordered_map> | ||
|
||
#ifndef _HANOI_H | ||
#define _HANOI_H | ||
|
||
class Hanoi | ||
{ | ||
public: | ||
Hanoi(const unsigned int &); | ||
void play(); | ||
|
||
private: | ||
std::vector <std::stack<int>> stacks; // the 3 stacks | ||
std::unordered_map <int, int> moves; // maps disks to their last position before current one | ||
int lrud; // least recently used disk | ||
|
||
unsigned int moveCounter; // tracks the number of moves | ||
unsigned int disksWidth; // used to format output | ||
|
||
void rHanoi(); // main, recursive function. Called by play | ||
std::stack<int> & getFrom(); // rHanoi helper | ||
std::stack<int> & getTo(std::stack<int> &); //rHanoi helper | ||
void move(std::stack<int> &, std::stack<int> &); // called by rHanoi | ||
void printStacks(); // called by move to output process | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include<hanoi.h> | ||
|
||
int main() | ||
{ | ||
const unsigned int DISKS = 3; | ||
Hanoi hanoi(DISKS); | ||
hanoi.play(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters