Created
June 14, 2016 11:52
-
-
Save Sangrail/a0cd8574fb84a1eb84b3ecb709d7464e to your computer and use it in GitHub Desktop.
Towers of Hanoi
This file contains 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
#include <iostream> | |
#include <map> | |
using namespace std; | |
map<int, char> lookup = {{1, 'a'}, {2, 'b'}, {3, 'c'}};; | |
void hanoi(int numDisks, int source, int destination, int open) | |
{ | |
if(numDisks>0) | |
{ | |
hanoi(numDisks-1, source, open, destination); | |
cout << "Moving " << lookup[numDisks] << " from " << source << " to " << destination << endl; | |
hanoi(numDisks-1, open, destination, open); | |
} | |
} | |
void main() | |
{ | |
hanoi(3, 1, 3, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment