Skip to content

Commit 6a31811

Browse files
Merge pull request #7 from kaggrwal/main
tower of hanoi algo added
2 parents 59cbf05 + 40df617 commit 6a31811

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tower_of_hanoi.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
long long toh(int N, int from, int to, int aux)
2+
{
3+
// Your code here
4+
long long count = 0;
5+
if (N == 1)
6+
{
7+
cout << "move disk " << N << " from rod " << from << " to rod " << to << endl;
8+
count = 1;
9+
return count;
10+
}
11+
12+
count += toh(N - 1, from, aux, to);
13+
cout << "move disk " << N << " from rod " << from << " to rod " << to << endl;
14+
count++;
15+
count += toh(N - 1, aux, to, from);
16+
return count;
17+
}
18+
19+
// question link :
20+
// https://practice.geeksforgeeks.org/problems/tower-of-hanoi-1587115621/1

0 commit comments

Comments
 (0)