Advertisement
alaminrifat

Queue in c++

Nov 3rd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int sizeq = 5, qu[5],front = -1, rear = -1;
  4.  
  5. bool isFull()
  6. {
  7.     if(rear==(sizeq-1)) return true;
  8.     else return false;
  9. }
  10. bool isEmpty()
  11. {
  12.     if(rear<0) return true;
  13.     else return false;
  14. }
  15.  
  16. void enq(int n)
  17. {
  18.     if(isFull()) cout<<"Overflow\n";
  19.     else if(isEmpty())
  20.     {
  21.         front=0;
  22.         rear=0;
  23.         qu[rear]=n;
  24.     }
  25.     else
  26.     {
  27.         rear++;
  28.         qu[rear]=n;
  29.     }
  30. }
  31. void dq(){
  32.     if(isEmpty()) cout<<"Underflow\n";
  33.     else {
  34.         front++;
  35.     }
  36. }
  37. void display(){
  38.     if(isEmpty()){
  39.        cout<<"Underflow\n";
  40.     }
  41.     else if(isFull()) {
  42.         cout <<"Overflow\n";
  43.     }
  44.     else{
  45.         cout<<"Queue is :: \n  ";
  46.         for (int i = front; i <= rear ; i++ ){
  47.             cout<<qu[i]<<" ";
  48.         }
  49.     }
  50. }
  51.  
  52. int main()
  53. {
  54.  
  55.     enq(5);
  56.     enq(6);
  57.     enq(7);
  58.     enq(8);
  59.     dq();
  60.     display();
  61.     return 0;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement