Question: Please help with moveDisk and isPuzzleSolved functions to be used to help user make moves and solve a tower of hanoi puzzle given this program
Please help with moveDisk and isPuzzleSolved functions to be used to help user make moves and solve a tower of hanoi puzzle given this program class Stack
public:
Stack;
~Stack;
bool isEmpty;
bool isFull;
void pushint val;
int pop;
int count;
int peekint pos;
void changeint pos, int val;
void display;
private:
int top;
int arr;
;
using namespace std;
Stack::Stack
top ;
for int i ; i ; i
arri;
Stack::~Stack
bool Stack::isEmpty
iftop
cout is empty" endl;
return true;
else
cout is not empty." endl;
return false;
bool Stack::isFull
iftop
cout is full." endl;
return true;
else
cout is not full." endl;
return false;
void Stack::pushint val
if isFull
cout "Overflow" endl;
else
top;
arrtop val;
int Stack::pop
if isEmpty
cout "Stack underflow" endl;
return ;
else
int popValue arrtop;
arrtop;
top;
return popValue;
int Stack::count
return top ;
int Stack::peekint pos
if isEmpty
cout "Stack underflow" endl;
return ;
else
return arrpos;
void Stack::changeint pos, int val
arrpos val;
cout "Value changed at position pos endl;
void Stack::display
cout "All items in stack are:" endl;
for int i top; i ; i
cout arri endl;
void towerOfHanoiint disks, Stack &source, Stack &auxiliary, Stack &destination
if disks
int disk source.pop;
destination.pushdisk;
cout "Move disk disk from Tower &source to Tower &destination endl;
return;
towerOfHanoidisks source, destination, auxiliary;
int disk source.pop;
destination.pushdisk;
cout "Move disk disk from Tower &source to Tower &destination endl;
towerOfHanoidisks auxiliary, source, destination;
void moveDiskStack& towerA, Stack& towerB, Stack& towerC, int fromTower, int toTower
int top top;
if fromTower A
top towerA.pop;
else if fromTower B
top towerB.pop;
else if fromTower C
top towerC.pop;
if toTower A
top towerA.pop;
else if toTower B
top towerB.pop;
else if toTower C
top towerC.pop;
if top
towerA.pushtop;
else if top
towerA.pushtop;
else if top top
if fromTower A && toTower B
towerB.pushtop;
else if fromTower B && toTower A
towerA.pushtop;
else if fromTower A && toTower C
towerC.pushtop;
else if fromTower C && toTower A
towerA.pushtop;
else if fromTower B && toTower C
towerC.pushtop;
else if fromTower C && toTower B
towerB.pushtop;
else
if fromTower A && toTower B
towerB.pushtop;
else if fromTower B && toTower A
towerC.pushtop;
else if fromTower A && toTower C
towerC.pushtop;
bool isPuzzleSolvedconst Stack& towerC, int numDisks
return ;
int main
switch choice
case :
Selfsolving program
towerOfHanoinumDisks towerA, towerB, towerC;
break;
case :
Help the user move discs between towers as directed
int fromTower, toTower;
while isPuzzleSolvedtowerC numDisks
cout "Enter the move eg A B to move a disk from Tower A to Tower B: ;
cin fromTower toTower;
moveDisktowerA towerB, towerC, fromTower, toTower;
std::cout "Congratulations! You solved the puzzle." std::endl;
break;
default:
std::cout "Invalid choice" std::endl;
break;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
