Skip to content

Commit f891f1c

Browse files
authored
Tower of Hanoi
1 parent 7f7b731 commit f891f1c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

towerofhanoi.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
using namespace std;
4+
void towerofhanoi(int n, char src, char des, char help)
5+
{
6+
if (n == 0)
7+
return;
8+
towerofhanoi(n - 1, src, help, des);
9+
cout << "Move from " << src << " to " << des << endl;
10+
towerofhanoi(n - 1, help, des, src);
11+
}
12+
int main(int argc, char const *argv[])
13+
{
14+
towerofhanoi(3, 'A', 'B', 'C');
15+
return 0;
16+
}

0 commit comments

Comments
 (0)