C++ version ¶
- 개발자 : 나휘동
- Recusive Function Call 사용
~cpp #include <iostream.h> void hanoi(const int n, int x, int y, int z); int count = 0; void main() { hanoi(4, 1, 2, 3); cout << "Steps : " << count << endl; } void hanoi(const int n, int x, int y, int z) { if ( n == 1){ cout << x << "->" << y << endl; count++; } else{ hanoi(n-1, x, y, z); hanoi(1, x, z, y); hanoi(n-1, y, z, x); } }