Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Print_stage(string por, Stack& a, Stack& b, Stack& c){
- for(int i=0;i<por.length();i++){
- if(por[i]=='a'){
- cout<<'-';
- a.Print();
- cout<<"-|";
- cout<<endl;
- }
- if(por[i]=='b'){
- cout<<'-';
- b.Print();
- cout<<"-|";
- cout<<endl;
- }
- if(por[i]=='c'){
- cout<<'-';
- c.Print();
- cout<<"-|";
- cout<<endl;
- }
- cout<<endl;
- }
- }
- void switch_disk(Stack& a,Stack& b){
- b.PushBack(a.Pop());
- }
- void tow(int h, Stack& a,Stack& b,Stack& c,string por,bool boo=0){
- if (h==1){switch_disk(a,b); }
- else{
- if(!boo){
- tow(h-1, a, c, b,"acb",1);
- Print_stage(por,a,b,c);
- system("Pause");
- switch_disk(a, b);
- Print_stage(por,a,b,c);
- system("Pause");
- tow(h-1, c, b, a,"cba",1);
- Print_stage(por,a,b,c);
- system("Pause");
- }
- if(boo){
- tow(h-1, a, c, b,"abc",0);
- Print_stage(por,a,b,c);
- system("Pause");
- switch_disk(a, b);
- Print_stage(por,a,b,c);
- system("Pause");
- tow(h-1, c, b, a,"abc",0);
- Print_stage(por,a,b,c);
- system("Pause");
- }
- }
- }
- void main(){
- Stack a,b,c;
- for(int i=8;i>0;i--)
- a.PushBack(i);
- Print_stage("abc",a,b,c);
- system("Pause");
- tow(a.Count(),a,b,c,"abc");
- system("Pause");
- }
Add Comment
Please, Sign In to add comment