Implementation of QUEUE using Linear Array in C++ Language:

#include <iostream>
using namespace std;
#define size 5
class queue
{
  int a[size];
  int rear,front;
  public:
  queue()
  {
      front=-1;
      rear=-1;
  }
  void enqueue(int value)
  {
     if( front = rear == -1)
     {
         front++;
         rear++;
      a[rear]=value;
      }
      else if(rear == size)

      {
          cout<<"queue is full";
      }
      else
      {
          rear++;
          a[rear]=value;
      }
  }    
      void dequeue()
      {
          
          if(front == -1 && rear == -1)
          {
              cout<<"queue empty";
          }
         else if(front == size && rear == size)
          {
              front=-1;
              rear=-1;
          }
          else if(front == rear)
          {
               front=-1;
              rear=-1;
         }
        else
        {
            front = front+1;;
        }
      }
      void display()
      {
        for(int i=front;i<=rear;i++)
          cout<<a[i]<<" ";  
      }
  };

int main() 
{
    queue q;
    int x,j;
    cin>>x;
    for(int i=1;i<=x;i++)
    {
        cin>>j;
        q.enqueue(j);
    }
 q.display();
 cout<<endl;
  q.dequeue();
   q.dequeue();
    q.display();
}



Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

2 comments:

  1. What is this faltu code?

    ReplyDelete
  2. For providing food the most precise type of data, realizing setting isn't sufficient. The assistance of the organization is likewise fundamental.machine learning course in pune

    ReplyDelete

Thanks
Mukesh Rajput