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

Queue Program in C

This C program implements a menu-driven queue system with options for enqueue, dequeue, display, and exit. It handles queue overflow and underflow conditions, providing user feedback for each operation. The program continues to prompt for user input until the exit option is selected.
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)
3 views2 pages

Queue Program in C

This C program implements a menu-driven queue system with options for enqueue, dequeue, display, and exit. It handles queue overflow and underflow conditions, providing user feedback for each operation. The program continues to prompt for user input until the exit option is selected.
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

// Menu driven program in C

#include <stdio.h>

// Driver code
int main() {
// Choice variable
int choice = -1,n=5,rear=-1,front=-1,item,queue[10],i;

// Menu display
printf("MENU:\n1. Enqueue \n2. Enqueue\n3. Display \n 4. Exit");

// Infinite Loop for choice input


while(1){
printf("\nEnter your choice:");
scanf("%d", &choice);

// If-else ladder
if(choice == 1){
printf("> You choose ENQUEUE operation!\n");
if(rear==n-1){
printf("\n Sorry !!! Queue Overflow..!\n");

}
else {

printf("\n Enter your item: ");


scanf("%d",&item);
rear=rear+1;

queue[rear]=item;
printf("\n %d has been Inserted !!",item);
if(rear==0)
front=0;
}

}
else if (choice == 2){
printf("> You choose DEQUEUE operation!!\n");
if(front==-1 || rear==-1 || front==rear+1){
printf("\n Sorry !!! Queue Underflow..!\n");

else{
item=queue[front];
printf("\n Item %d has been deleted !!! \n",item);
front=front+1;

else if (choice == 3){


printf("> You choose display operation!!\n");
if(front==-1 || rear==-1 || front==rear+1){
printf("\n Sorry !!! queue Underflow..!\n");

else {
for(i=front;i<=rear;i++)
printf("%d ",queue[i]);
}

}
else if (choice == 4){
printf("BYE!!!\n");
// Termination of the Loop using break statement
break;
}
else{
printf("> Invalid Input\n");
}
}
return 0;
}

You might also like