Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- #define MAX 5
- class stack
- {
- private:
- int arr[MAX];
- int top;
- public:
- stack()
- {
- top=-1;
- }
- void push(int num)
- {
- top++;
- if(top<MAX)
- {
- arr[top]=num;
- }
- else
- {
- cout << "full";
- top--;
- }
- }
- int pop()
- {
- if(top==-1)
- {
- cout << "empty";
- return NULL;
- }
- else
- {
- int x=arr[top];
- arr[top]=NULL;
- top--;
- return x;
- }
- }
- };
- int main()
- {
- stack a;
- int y;
- for(int ctr=0;ctr<5;ctr++)
- {
- cin >> y;
- a.push(y);
- }
- for(int ctr=0;ctr<5;ctr++)
- {
- cout << a.pop() << " ";
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement