C ++ IMPLEMENTATION OF QUEUE USING CLASSES :
Print this page
 

#include <iostream.h>
#include <conio.h>

#define MAX 5 // MAXIMUM CONTENTS IN QUEUE

class queue
{
private:
    int t[MAX];
    int al; // Addition End
    int dl; // Deletion End
public:
queue()
{
    dl=-1;
    al=-1;
}

void del()
{
int tmp;
if(dl==-1)
{

cout<<"Queue is Empty";
}
else
{
        for(int j=0;j<=al;j++)
        {
            if((j+1)<=al)
            {
                tmp=t[j+1];
                t[j]=tmp;
            }
            else
            {
                al--;

            if(al==-1)
                dl=-1;
            else
                dl=0;
            }
        }
}
}

  void add(int item)
{
    if(dl==-1 && al==-1)
    {
        dl++;
        al++;
    }
else
{
        al++;
        if(al==MAX)
    {
            cout<<"Queue is Full\n";
            al--;
            return;
        }
    }
    t[al]=item;

}

void display()
{
    if(dl!=-1)
{
    for(int i=0;i<=al;i++)
    cout<<t[i]<<" ";
}
else
    cout<<"EMPTY";
}

};
   
Prev