You are on page 1of 3

#include<stdio.

h>
#include<iostream.h>
#include<conio.h>
class queue
{
public:
int rear,front,arr[5];
void addq(int);
int delq();
queue();
};
queue::queue()
{
rear=-1;
front=-1;
}
void queue::addq(int val)
{
rear++;
if(rear>4)
{
cout<<"ERROR:This value can't be stored in the queue.\n\tThe queue is full."<<endl;
}
else
{
cout<<"Value added in the queue."<<endl;
arr[rear]=val;
}
}
int queue::delq()
{
int d;
if(rear==-1)
{
cout<<"the queue is empty"<<endl;
return NULL;
}
else
{
front++;
d=arr[front];
return d;
arr[front]=NULL;
}
}

void main()
{
clrscr();
cout<<" ****A PROGRAM FOR IMPLEMENTING QUEUE AS AN
ARRAY****"<<endl;
queue q;
int i,j;
cout<<"enter values to store in the queue:"<<endl;
for(i=0;i<6;i++)
{
cin>>j;
q.addq(j);
}
cout<<endl<<"the values are:"<<endl;
for(i=0;i<5;i++)
{
cout<<q.delq();
cout<<endl;
}
getche();
}

You might also like