Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool isfull(int top, int size)
- {
- return ((top+1)==size);
- }
- bool isempty(int top)
- {
- return (top==-1);
- }
- bool push(int &top, int *stack, int size, int x)
- {
- if(isfull(top, size))
- return 0;
- top++;
- stack[top]=x;
- return 1;
- }
- bool pop(int &top, int *stack, int &y)
- {
- if(isempty(top))
- return 0;
- y=stack[top];
- top--;
- return 1;
- }
- void showtop(int *stack, int top)
- {
- if(isempty(top))
- cout<<"Pusty"<<endl;
- else
- cout<<"top: "<<stack[top]<<endl;
- }
- int main()
- {
- int size=5;
- int stack[5];
- int top=-1;
- int y=0;
- push(top, stack, size, 1);
- showtop(stack, top);
- push(top, stack, size, 2);
- showtop(stack, top);
- push(top, stack, size, 3);
- showtop(stack, top);
- push(top, stack, size, 4);
- showtop(stack, top);
- push(top, stack, size, 5);
- showtop(stack, top);
- push(top, stack, size, 6);
- pop(top, stack, y);
- cout<<y<<endl;
- pop(top, stack, y);
- cout<<y<<endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement