Advertisement
jkavart

Untitled

Feb 10th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. void Hanoi2(string S, string A1, string A2, string A3, string D, int n, bool firstTime=true)
  2. {
  3.     if(n==1)
  4.     {
  5.         cout<<n<<" from "<<S<<" to "<<A1<<endl;
  6.         Hanoi1(S, A1, A2, A3, D, n);
  7.     }
  8.     if(n>=2)
  9.     {
  10.         Hanoi2(S, A1, A2, A3, D, n-1, false);
  11.         cout<<n<<" from "<<S<<" to "<<A1<<" to "<<A2<<endl;
  12.         Hanoi1(S, A3, A2, A1, D, n-1);
  13.         cout<<n<<" from "<<A2<<" to "<<A3<<endl;
  14.         if(firstTime)
  15.         {
  16.             cout<<n<<"from "<<A3<<" to "<<D<<endl;
  17.             Hanoi3(S, A1, A2, A3, D, n-1);
  18.         } else
  19.         {
  20.             Hanoi1(S, A1, A2, A3, D, n-1);
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement