Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Towers of Hanoi
- */
- void move(int disk, char source, char destination) {
- cout << "Move disk " << disk << " from rod " << source << " to rod " << destination << endl;
- }
- void towersOfHanoi(int n, char source, char destination, char auxiliary) {
- if (n == 1) {
- move(n, source, destination);
- return;
- }
- towersOfHanoi(n - 1, source, auxiliary, destination);
- move(n, source, destination);
- towersOfHanoi(n - 1, auxiliary, destination, source);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement