- Codice:
void hanoi(int n, char a, char c, char b)
{
if (n == 1)
cout << a << " - " << c << endl;
else
{
hanoi(n - 1, a, b, c);
cout << a << " - " << c << endl;
hanoi(n - 1, b, c, a);
}
}
void hanoi(int n, char a, char c, char b)
{
if (n == 1)
cout << a << " - " << c << endl;
else
{
hanoi(n - 1, a, b, c);
cout << a << " - " << c << endl;
hanoi(n - 1, b, c, a);
}
}
1 | |
2 | |
3 | |
| | |
2 | |
3 | 1
| | |
| | |
3 2 1
| | |
| 1 |
3 2 |
| | |
| 1 |
| 2 3
| | |
| | |
1 2 3
| | |
| | 2
1 | 3
| | 1
| | 2
| | 3
Visitano il forum: Nessuno e 1 ospite