Created
January 5, 2017 11:46
-
-
Save enif-lee/aaa237253c5e4fa4a9cc172c4d1a538d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void move(int from, int to){ | |
| printf("\nMove from %d to %d", from, to); | |
| } | |
| // n개의 원반을 from 에서 by를 거쳐 to로 옮긴다. | |
| void hanoi(int n, int from, int by, int to){ | |
| if (n == 1) | |
| move(from, to); | |
| else{ | |
| hanoi(n - 1, from, to, by); // 1번 N-1개의 원반을 기둥3을 거쳐 2로 옮긴다. | |
| move(from, to); // 2번 기둥 1에서 1개의 원반을 기둥 3으롱 롬긴다. | |
| hanoi(n - 1, by, from, to); // 3번 기둥 2에서 N-1개의 원반을 기둥 3으로 옮긴다. | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment