Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Hanoi2(string S, string A1, string A2, string A3, string D, int n, bool firstTime=true)
- {
- if(n==1)
- {
- cout<<n<<" from "<<S<<" to "<<A1<<endl;
- Hanoi1(S, A1, A2, A3, D, n);
- }
- if(n>=2)
- {
- Hanoi2(S, A1, A2, A3, D, n-1, false);
- cout<<n<<" from "<<S<<" to "<<A1<<" to "<<A2<<endl;
- Hanoi1(S, A3, A2, A1, D, n-1);
- cout<<n<<" from "<<A2<<" to "<<A3<<endl;
- if(firstTime)
- {
- cout<<n<<"from "<<A3<<" to "<<D<<endl;
- Hanoi3(S, A1, A2, A3, D, n-1);
- } else
- {
- Hanoi1(S, A1, A2, A3, D, n-1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement