Created
May 8, 2018 05:36
-
-
Save patelpreet422/2814a1b9d8fe309613045c07e63fc4d4 to your computer and use it in GitHub Desktop.
Tower of hanoi
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
#include <iostream> | |
void toh(char from, char to, char intermediate, int noofdisk) | |
{ | |
if(noofdisk == 1) | |
std::cout << "Move " << noofdisk << " from " << from << " to " << to << '\n'; | |
else { | |
toh(from, intermediate, to, noofdisk-1); | |
std::cout << "Move " << noofdisk << " from " << from << " to " << to << '\n'; | |
toh(intermediate, to, from, noofdisk-1); | |
} | |
} | |
int main() | |
{ | |
toh('A', 'C', 'B', 6); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment