IMPLEMENTATION OF QUEUE USING ARRAY IN C

#include<stdio.h>
#define MAX 4
int front=-1,rear=-1;
int q[MAX];
void enqueue();
void dequeue();
int diplay();
main()
{
int ch;
do
{
printf(“\nmenu\n1.enqueue\n2.dequeue\n3.display\n4.exit\n”);
printf(“entr th choice\n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1:enqueue();
break;
case 2:dequeue();
break;
case 3:display();
break;
case 4:break;
}
}while(ch!=4);
}
void enqueue()
{
int n;
if(rear>=MAX-1)
{
printf(“the queue is full\n”);

}
else
{
printf(“enter the number\n”);
scanf(“%d”,&n);
rear+=1;
q[rear]=n;
}
}
void dequeue()
{
if(front==rear)
printf(“the queue is empty\n”);
else
{
front+=1;
}
}
int display()
{
int i;
for(i=front+1;i<=rear;i++)
printf(“\t%d”,q[i]);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s