Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define mx 2
- int i(0);
- class node
- {
- public:
- int info;
- node *link;
- };
- class stackk
- {
- node *head;
- public:
- stackk()
- {
- head = NULL;
- }
- void push(int val)
- {
- node *ptr = new node();
- ptr->info = val;
- ptr->link = head;
- head = ptr;
- i++;
- }
- int pop()
- {
- int val = head->info;
- head = head->link;
- i--;
- return val;
- }
- bool isEmpty()
- {
- if(head == NULL)
- {
- cout<<"\nStack Underflow!!!!\n\n";
- return true;
- }
- return false;
- }
- bool isFull()
- {
- if(i >= mx)
- {
- cout<<"\nStack Overflow!!!\n\n";
- return true;
- }
- return false;
- }
- };
- int main()
- {
- int i, j, k, n;
- stackk stk1;
- while(true)
- {
- cout<<"Stack Operations:\n1. Push\n2. Pop\n0. Exit\nEnter a number from 0 to 2 : ";
- cin>>k;
- if(k == 1)
- {
- if(!stk1.isFull())
- {
- cout<<"\nEnter the value you want to push : ";
- cin>>n;
- stk1.push(n);
- cout<<endl;
- }
- }
- else if(k == 2)
- {
- if(!stk1.isEmpty())
- cout<<"\nThe top of the stack : "<<stk1.pop()<<endl<<endl;;
- }
- else if(k == 0)
- break;
- else
- cout<<"\nEnter correct number!!!\n\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement