forked from itsprueba/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTower_of_hanoi.cpp
More file actions
48 lines (42 loc) · 1.05 KB
/
Tower_of_hanoi.cpp
File metadata and controls
48 lines (42 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//TOWER OF HANOI
/////////////////LIBRARIES///////////////////
#include<bits/stdc++.h>
using namespace std;
/////////////////////CLASSES//////////////////
//////////////U D FUNCTIONS//////////////////////////////
void toi(int disc,int int_pole,int final_pole,int helpp);
////////////////MAIN///////////////////////////////////
int main()
{
int disc;
cin>>disc;
int int_pole,final_pole,helpp;
cin>>int_pole>>final_pole>>helpp;
toi(disc,int_pole,final_pole,helpp);
//3 1 3 2
}
/////////////////////////OUTPUT///////////////////////////////
//3 1 3 2
//1-1 to 3
//2-1 to 2
//1-3 to 2
//3-1 to 3
//1-2 to 1
//2-2 to 3
//1-1 to 3
/////////////////////////FUNCTIONS//////////////////////////////
void toi(int disc,int int_pole,int final_pole,int helpp)
{
if(disc==1)
{
cout<<disc<<"-"<<int_pole<<" to "<<final_pole<<"\n";
return;
}
else
{
toi(disc-1,int_pole,helpp,final_pole);
cout<<disc<<"-"<<int_pole<<" to "<<final_pole<<"\n";
toi(disc-1,helpp,final_pole,int_pole);
return;
}
}