1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
void Move(int e, string x, string y, string z)
{
if (e ==1)
{
cout << "Move disk from tower " << x << " to tower " << z << endl;
}
else
cout<< "Move disk from tower " << x << " to tower " << y << endl;
}
void Hanoi(int n, string a, string b, string c)
{
if (n == 1)
Move(a,c);
else
Hanoi(n-1,a,c,b);
Move(a,b);
Hanoi(n-1,c,b,a);
}
int main()
{
int numofdisk;
cout << " *******WELCOME TO TOWERS OF HANOI******* " << endl;
cout << "Please specify the number of disks" << endl;
cin >> numofdisk;
Hanoi(numofdisk, "A", "B", "C");
system("Pause");
return 0;
}
|