0% found this document useful (0 votes)
2 views2 pages

C Queue Implementation in C Language

The document contains a C program that implements a simple queue using an array with basic operations such as enqueue, dequeue, and display. It defines a maximum size for the queue and handles overflow and underflow conditions. The main function provides a menu for user interaction to perform these operations.

Uploaded by

hidos59858
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

C Queue Implementation in C Language

The document contains a C program that implements a simple queue using an array with basic operations such as enqueue, dequeue, and display. It defines a maximum size for the queue and handles overflow and underflow conditions. The main function provides a menu for user interaction to perform these operations.

Uploaded by

hidos59858
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

#include<stdio.

h>
#include<stdlib.h>
#define M 5
int q[M],front = -1,rear = -1;
void enq(int e)
{
if(rear == M -1)
{
printf("\nOVERFLOW.. | QUEUE IS FULL YOU CANNOT ENTER NEW ELEMENTS ");
}
else
{
if(front == -1)
{
front = 0;
}
rear++;
q[rear] = e;
}
}
void deq()
{
if(front == -1 )
{
printf("\nUNDERFLOW.. || OUEUE IS EMPTY ");
}
else{

printf("\nDEQUEUED SUCCESFULLY : %d",q[front]);


front = front + 1;
}
}
void display()
{
if(front == -1 || front>rear)
{
printf("\nOUEUE IS EMPTY....");
}
else{
printf("\nQUEUE ELEMENTS IS : ");
for(int i=front;i<=rear;i++)
{
printf("%d ",q[i]);
}
}
}
int main()
{
int ch,a;
printf("PRESS 1 FOR ENQUEUE\nPRESS 2 FOR DEQUEUE\nPRESS 3 FOR DISPLAY THE QUEUE ELEMENTS\nPRESS 4 FOR
EXIT\n");
while(1)
{
printf("\nENTER CHOICE ");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nENTER THE ELEMENT YOU WANT TO ENTER IN QUEUE : ");
scanf("%d",&a);
enq(a);
break;
case 2:
deq();
break;
case 3:
display();
break;
case 4:
exit(0);
default:
printf("\nWRONG INPUT");
}
}
return 0;
}

You might also like