Question
Please help me solve this problem using C++ //Towers of Hanoi Game #include using namespace std; int main() { this_in = new Scanner(system_in); this_current =
Please help me solve this problem using C++
//Towers of Hanoi Game #include
int main() { this_in = new Scanner(system_in); this_current = 1; cout
//recursive function to move the disks around the pegs
{ move(1, Start, source, this_current); this_current++; // call the move function H1(n, 'Start', 'Aux1', 'Aux3', 'Aux2', 'Dest', this_current); //recursive function call move(1, dest, last, this_current); this_current++; //call the move function }
int H1(int numOfDisks, String Start, String source, String dest, String aux, String last, int current)
{ if (n == 1) { cout
else if (n == 2)
{ cout
//scenario if the num of disks is greater than 2
else if (n > 2) { this_current = H1(n - 1, Start, from_rod, source_rod, dest_rod, aux_rod, to_rod); if (move((this_rod)) then(n != 1) { move(n, from_rod, source_rod, to_rod); to_rod++; to_rod(move(n = 1)); } move(n, source_rod, aux_rod to_rod); to_rod++; to_rod = H1(n - 1, from_rod, dest_rod, source_rod, aux_rod, to_rod, to_rod); move(n, aux_rod, dest_rod, to_rod); to_rod++; if (dest_rod[n + 1] != 0) { move(n, dest_rod, last_rod, last_rod); to_rod++; dest_rod[n] = 1; } if (n == r) this == r; current = H1(n - 1, start_rod, source_rod, dest_rod, aux_rod, last_rod, last_rod); }; return 0; } void move(int aDisk, String source, String source, String dest, int currentStep) { cout
// Driver code
int main() { int n = 10; // Number of disks towerOfHanoi(n, 'Start', 'Aux1', 'Aux3', 'Aux2', 'Dest', this.current); return 0; }
1. Solve the Towers of Hanoi game for the following graph G (V.E) with y=[Start, Aux, Aux2, Aux3, Aux4, Dest) and E = {(Start, Aux1). (Aux1, Aux2), (Aux2, Aux3), (Aux3, AUX4), (Aux4, Auxl), (Aux 1, Dest)}. (a) Design an algorithm and determine the time and space complexities of moving n disk from Start to Dest. (b) Implement this algorithm whereby your program prints out each of the moves of every disk. Show the output for n-1, 2, 3, 4, 5, 6, 7, 8, 9, and 10. (If the output is too long, print ou only the first 100 and the last 100 moves.)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