Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int sizeq = 5, qu[5],front = -1, rear = -1;
- bool isFull()
- {
- if(rear==(sizeq-1)) return true;
- else return false;
- }
- bool isEmpty()
- {
- if(rear<0) return true;
- else return false;
- }
- void enq(int n)
- {
- if(isFull()) cout<<"Overflow\n";
- else if(isEmpty())
- {
- front=0;
- rear=0;
- qu[rear]=n;
- }
- else
- {
- rear++;
- qu[rear]=n;
- }
- }
- void dq(){
- if(isEmpty()) cout<<"Underflow\n";
- else {
- front++;
- }
- }
- void display(){
- if(isEmpty()){
- cout<<"Underflow\n";
- }
- else if(isFull()) {
- cout <<"Overflow\n";
- }
- else{
- cout<<"Queue is :: \n ";
- for (int i = front; i <= rear ; i++ ){
- cout<<qu[i]<<" ";
- }
- }
- }
- int main()
- {
- enq(5);
- enq(6);
- enq(7);
- enq(8);
- dq();
- display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement