PROGRAM TO IMPLEMENT INSERTION IN A QUEUE USING ARRAY

/*PROGRAM TO IMPLEMENT INSERTION IN A QUEUE USING ARRAY*/
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#define MAX 5
void main()
{
int i,a[MAX],rear=-1,n;
char ch;
clrscr();
do
{
if(rear>=MAX-1)
{
cout<<“Queue is full”<<endl;
break;
}
else
{
rear++;
cout<<“Enter the number to be inserted: “;
cin>>n;
a[rear]=n;
}
cout<<“Do you want to insert more numbers: “;
cin>>ch;
}while(ch==’y’||ch==’Y’);
cout<<“Elements of queue are: “<<endl;
for(i=0;i<=rear;i++)
{
cout<<a[i]<<“\t”;
}
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *