20 lines
No EOL
433 B
C
20 lines
No EOL
433 B
C
int printf(char* format, ...);
|
|
|
|
void move(char from_rod, char to_rod) {
|
|
printf("%c --> %c\n", from_rod, to_rod);
|
|
}
|
|
|
|
void hanoi(int n, char from_rod, char to_rod, char aux_rod) {
|
|
if (n == 1) {
|
|
move(from_rod, to_rod);
|
|
return;
|
|
}
|
|
hanoi(n - 1, from_rod, aux_rod, to_rod);
|
|
move(from_rod, to_rod);
|
|
hanoi(n - 1, aux_rod, to_rod, from_rod);
|
|
}
|
|
|
|
int main() {
|
|
int n = 3;
|
|
hanoi(n, 'A', 'C', 'B');
|
|
} |