TowerOfHanoi
hanoi.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <stack>
5 #include <string>
6 
13 class Rod {
14  int mCapacity;
15  std::string mName;
16  std::stack<int> mDisks;
17 
18 public:
19  Rod(std::string name, int capacity);
20  void push(int diskValue);
21  int pop();
22  bool isAtCapacity();
23  bool isEmpty();
24  friend class Hanoi;
25 };
26 
31 class Hanoi {
32  Rod start, dest, aux;
33  int mRequiredMoves;
34  int mDisks;
35  bool mPrintState;
36  void moveDisk(Rod &src, Rod &dest, std::ostream &out);
37  void printState(std::ostream &out);
38 
39 public:
40  Hanoi(int disks, bool printState);
41  void execute(std::ostream &out = std::cout);
42 };
Hanoi is a class that takes the action of moving disks between rods. It does this by encapsulates Rod...
Definition: hanoi.h:31
Hanoi(int disks, bool printState)
Initializes a Hanoi class with the size of the problem and whether we want to know state.
Definition: hanoi.cpp:54
void execute(std::ostream &out=std::cout)
A function that executes the number of disk moves and reports the move set.
Definition: hanoi.cpp:128
Rod is a class to maintains state about disk positions.
Definition: hanoi.h:13
bool isAtCapacity()
Checks if we have met the capacity limit.
Definition: hanoi.cpp:21
void push(int diskValue)
Definition: hanoi.cpp:25
Rod(std::string name, int capacity)
Initializes a Rod with a name and a capacity.
Definition: hanoi.cpp:13
bool isEmpty()
Definition: hanoi.cpp:23
int pop()
If the stack is not empty we will pop off the top disk.
Definition: hanoi.cpp:38