Created
April 13, 2021 06:02
-
-
Save Sustainability4/b1c6f8936ba93f558fc51728a1d7cad5 to your computer and use it in GitHub Desktop.
Tower of Hanoi Problem
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> | |
using namespace std; | |
#include <cmath> | |
// Change in the given string itself. So no need to return or print the changed string. | |
void towerOfHanoi(int n, char source, char auxiliary, char destination) { | |
// Power of Recursion | |
if (n == 0){ | |
return; | |
} | |
towerOfHanoi(n-1, source, destination, auxiliary); | |
cout<< source << " " << destination << endl ; | |
towerOfHanoi(n-1, auxiliary, source, destination ); | |
} | |
int main() { | |
int n; | |
cin >> n; | |
towerOfHanoi(n, 'a', 'b', 'c'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment