Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class stack
- {
- public:
- int *arraystack;
- int arraysize;
- int top;
- stack(int);
- void push(int);
- int pop();
- bool isfull();
- bool isempty();
- int size();
- int peek();
- };
- int stack::peek()
- {
- if (!isempty())
- return arraystack[top];
- }
- int stack::size()
- {
- return top + 1;
- }
- stack::stack(int size)
- {
- arraystack=new int [size];
- arraysize=size;
- top=-1;
- }
- void stack::push(int num)
- {
- if(isfull())
- {
- cout<<"the stack is full"<<endl;
- }
- else
- {
- top++;
- arraystack[top]=num;
- }
- }
- int stack::pop()
- {
- if(isempty())
- {
- cout<<"array is empty"<<endl;
- }
- else
- {
- return arraystack[top--];
- }
- }
- bool stack::isfull()
- {
- if(arraysize-1==top)
- return true;
- else
- return false;
- }
- bool stack::isempty()
- {
- if(top==-1)
- return true;
- else
- return false;
- }
- class queue:public stack
- {
- public:
- stack s1,s2;
- // Enqueue function of Queue
- void enqueue(int val)
- {
- s1.push(val);
- cout << "enqueued :" << val << endl;
- }
- // Dequeue function of Queue
- void dequeue()
- {
- if (s2.isempty())
- {
- while(!s1.isempty())
- {
- s2.push(s1.peek());
- s1.pop();
- }
- }
- if(!s2.isempty())
- {
- cout << "dequeued :" << s2.peek() << endl;
- s2.peek();
- }
- else
- {
- cout << "Underflow "<< endl;
- }
- }
- // Front
- void front()
- {
- if (s2.isempty())
- {
- while(!s1.isempty())
- {
- s2.push(s1.peek());
- s1.pop();
- }
- }
- if(!s2.isempty())
- {
- cout << "top :" << s2.peek() << endl;
- }
- else
- {
- cout << "Underflow "<< endl;
- }
- }
- // Empty
- bool isEmpty()
- {
- if(s1.isempty() && s2.isempty())
- {
- cout << "Empty "<< endl;
- return true;
- }
- cout << "Not Empty "<< endl;
- return false;
- }
- // Size
- int size()
- {
- int s = s1.size() + s2.size();
- cout << "size :" << s << endl;
- return s;
- }
- };
- int main()
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement