Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help with tower of hanoi puzzle, I need help creating a switch statement that prompts users for the moves thy want and moves elements
Please help with tower of hanoi puzzle, I need help creating a switch statement that prompts users for the moves thy want and moves elements between stacks to solve the puzzle. 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;
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;
int main
int numDisks ; Change the number of disks here
Stack towerA, towerB, towerC;
char answer;
int option, choice;
cout "Here are the options for sloving the Tower of Hanoi: endl;
cout Self solving program. endl;
cout Try and solve the puzzle yourself. endl;
cin choice;
switchchoice
case :
Push disks onto the first tower Tower A
for int i numDisks; i ; i
towerA.pushi;
cout "Initial configuration:" endl;
towerA.display; Display the initial configuration
Solve Tower of Hanoi
towerOfHanoinumDisks towerA, towerB, towerC;
cout "Final configuration:" endl;
towerC.display; Display the final configuration in the destination tower
break;
case :
Help here moving discs between towers as directed by the user
cout "what move will you make? endl;
cout move disc from Tower A to Tower B endl;
cout move disc From Tower A to Tower C endl;
cin choice;
switchchoice
case :
break;
case :
break;
break;
whileoption ;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started