Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<iostream>
- #include<stack>
- using namespace std;
- #define MAX 1000;
- struct stack{
- int arr[1000];
- int top;
- }A,B,C;
- int isFull1()
- {
- if(A.top==(1000-1))
- {
- return 1;
- }
- return 0;
- }
- int isEmpty1()
- {
- if(A.top==-1)
- {
- return 1;
- }
- return 0;
- }
- void push1(int value)
- {
- if(!isFull1())
- {
- A.top=A.top+1;
- A.arr[A.top]=value;
- }
- }
- void pop1()
- {
- if(!isEmpty1())
- {
- // return st[top];
- A.top=A.top-1;
- }
- }
- int peek1()
- {
- if(!isEmpty1())
- {
- // printf("%d",st[top]);
- return A.arr[A.top];
- }
- return -1;
- }
- int isFull2()
- {
- if(B.top==(1000-1))
- {
- return 1;
- }
- return 0;
- }
- int isEmpty2()
- {
- if(B.top==-1)
- {
- return 1;
- }
- return 0;
- }
- void push2(int value)
- {
- if(!isFull2())
- {
- B.top=B.top+1;
- B.arr[B.top]=value;
- }
- }
- void pop2()
- {
- if(!isEmpty2())
- {
- // return st[top];
- B.top=B.top-1;
- }
- }
- int peek2()
- {
- if(!isEmpty2())
- {
- // printf("%d",st[top]);
- return B.arr[B.top];
- }
- return -1;
- }
- int isFull3()
- {
- if(C.top==(1000-1))
- {
- return 1;
- }
- return 0;
- }
- int isEmpty3()
- {
- if(C.top==-1)
- {
- return 1;
- }
- return 0;
- }
- void push3(int value)
- {
- if(!isFull3())
- {
- C.top=C.top+1;
- C.arr[C.top]=value;
- }
- }
- void pop3()
- {
- if(!isEmpty3())
- {
- // return st[top];
- C.top=C.top-1;
- }
- }
- int peek3()
- {
- if(!isEmpty3())
- {
- // printf("%d",st[top]);
- return C.arr[C.top];
- }
- return -1;
- }
- int main()
- {
- A.top=-1;
- B.top=-1;
- C.top=-1;
- int n,a;
- cin>>n;
- // stack<int>A,B,C;
- for(int i=0;i<n;i++)
- {
- cin>>a;
- push1(a);
- }
- while(!isEmpty1())
- {
- int k = peek1();
- pop1();
- while(!isEmpty2()&& peek2()>k)
- {
- push1(peek2());
- pop2();
- }
- push2(k);
- }
- while(!isEmpty2())
- {
- int z=peek2();
- push3(z);
- pop2();
- }
- cout<<"\n";
- cout<<"Condition of stack C :";
- while(!isEmpty3())
- {
- cout<<peek3()<<" ";
- pop3();
- }
- cout<<"\n";
- cout<<"Condition of stack B: Empty"<<"\n";
- cout<<"Condition of stack A: Empty";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement