Guest User

Untitled

a guest
Jul 16th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. void Print_stage(string por, Stack& a, Stack& b, Stack& c){
  2.     for(int i=0;i<por.length();i++){
  3.         if(por[i]=='a'){
  4.             cout<<'-';
  5.             a.Print();
  6.             cout<<"-|";
  7.             cout<<endl;
  8.         }
  9.         if(por[i]=='b'){
  10.             cout<<'-';
  11.             b.Print();
  12.             cout<<"-|";
  13.             cout<<endl;
  14.         }
  15.         if(por[i]=='c'){
  16.             cout<<'-';
  17.             c.Print();
  18.             cout<<"-|";
  19.             cout<<endl;
  20.         }
  21.         cout<<endl;
  22.     }
  23. }
  24. void switch_disk(Stack& a,Stack& b){
  25.     b.PushBack(a.Pop());
  26. }
  27. void tow(int h, Stack& a,Stack& b,Stack& c,string por,bool boo=0){
  28.     if (h==1){switch_disk(a,b); }
  29.     else{
  30.         if(!boo){
  31.             tow(h-1, a, c, b,"acb",1);
  32.             Print_stage(por,a,b,c);
  33.             system("Pause");
  34.             switch_disk(a, b);
  35.             Print_stage(por,a,b,c);
  36.             system("Pause");
  37.             tow(h-1, c, b, a,"cba",1);
  38.             Print_stage(por,a,b,c);
  39.             system("Pause");
  40.         }
  41.         if(boo){
  42.             tow(h-1, a, c, b,"abc",0);
  43.             Print_stage(por,a,b,c);
  44.             system("Pause");
  45.             switch_disk(a, b);
  46.             Print_stage(por,a,b,c);
  47.             system("Pause");
  48.             tow(h-1, c, b, a,"abc",0);
  49.             Print_stage(por,a,b,c);
  50.             system("Pause");
  51.         }
  52.     }
  53. }
  54. void main(){
  55.     Stack a,b,c;
  56.     for(int i=8;i>0;i--)
  57.         a.PushBack(i);
  58.     Print_stage("abc",a,b,c);
  59.     system("Pause");
  60.     tow(a.Count(),a,b,c,"abc");
  61.     system("Pause");
  62. }
Add Comment
Please, Sign In to add comment