Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int top=-1;
- int a[5];
- int front=-1;
- int rear=-1;
- void push(int x)
- {
- if(top==4)
- {
- cout<<"Stack is full"<<endl;
- }
- else
- {
- a[top+1]=x;
- top++;
- }
- }
- void pop()
- {
- if(top==-1)
- {
- cout<<"No values in stack"<<endl;
- }
- else
- {
- top=top-1;
- }
- }
- void enqueue(int x)
- {
- if(rear==4)
- {
- cout<<"List is full"<<end;
- }
- else
- {
- if(front==-1)
- {
- front=0;
- rear=0;
- a[rear]=x;
- }
- else{
- a[rear+1]=x;
- rear++;
- }
- }
- }
- void dequeue()
- {
- if(front==-1)
- {
- cout<<"No values in the list"<<endl;
- }
- else
- {
- if(front==rear)
- {
- front=-1;
- rear=-1;
- }
- else{
- front++;
- }
- }
- }
- void display()
- {
- for(int i=front;i<=rear;i++)
- {
- cout<<a[i]<<endl;
- }
- }
- int main()
- {
- push(10);
- push(20);
- pop();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement