Skip to content

Instantly share code, notes, and snippets.

@patelpreet422
Created May 8, 2018 05:36
Show Gist options
  • Save patelpreet422/2814a1b9d8fe309613045c07e63fc4d4 to your computer and use it in GitHub Desktop.
Save patelpreet422/2814a1b9d8fe309613045c07e63fc4d4 to your computer and use it in GitHub Desktop.
Tower of hanoi
#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