#include <iostream.h>
int Gbsx (char & L, Char & R)// function to Change Order
{char T;
T= L;
L= R;
R= T;
Return0;
}
void Move (int n, char A, char B, char c)// Hanoi core function
{
if (n = = 1)
{
cout<< " move " << a << " to " << c << Endl;
}
Else
{Gbsx (b, c); change the order of the back two
Move (N-1, A, b, c); implementing its steps with recursion
Gbsx (b, c); change the order of the two in the back.
Move (1, a, b, c);
Gbsx (A, b); change the order of the previous two
Move (N-1, A, b, c); implementing its steps with recursion
}
}
int sum (int n)// function to calculate the number of steps
{
INTs = 1;
for (int i = 1; I <= n; i++)
{
S= s*2;
}
returns-1;
}
void Main ()// main function
{int n = 1;
cout<< " Please enter the number of plates you have placed " << Endl;
cin>> N; the input value is assigned to N to implement the
cout<< " total " << sum (n) << " step ," << "step to " << Endl;
Move (n, ' A ', ' B ', ' C '); calling functions
}
Hanoi Tower problem C + + implementation