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

C Queue Implementation in C Language

This document contains a C program that implements a queue data structure with operations to insert, delete, and display elements. It defines a maximum size for the queue and handles overflow and underflow conditions. The main function provides a menu for users to interact with the queue through a simple command-line interface.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

C Queue Implementation in C Language

This document contains a C program that implements a queue data structure with operations to insert, delete, and display elements. It defines a maximum size for the queue and handles overflow and underflow conditions. The main function provides a menu for users to interact with the queue through a simple command-line interface.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Queue

#include <stdio.h>
#include<stdlib.h>
#define MAX 50
void insert();
void delete();
void display();
int queue_array[MAX];
int rear = - 1;
int front = - 1;
int main()
{
int choice;
 
printf("[Link] element to queue \n");
printf("[Link] element from queue \n");
printf("[Link] all elements of queue\n");
printf("[Link] n");
do
{
printf("Enter your choice : ");
scanf("%d", &choice);
 
switch(choice)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("Wrong choice n");
}
}    while(choice!=4);
}
void insert()
{
int item;
if(rear == MAX - 1)
printf("Queue Overflow n");
else
{
if(front== - 1)
front = 0;
printf("Inset the element in queue : ");
scanf("%d", &item);
rear = rear + 1;
queue_array[rear] = item;
}
}
void delete()
{
if(front == - 1 || front > rear)
{
printf("Queue Underflow \n");
return;
}
else
{
printf("Element deleted from queue is :%d\n",
queue_array[front]);
front = front + 1;
}
}
void display()
{
int i;
if(front == - 1)
printf("Queue is empty n");
else
{
printf("Queue is : n");
for(i = front; i <= rear; i++)
printf("%d ", queue_array[i]);
printf("n");
}
}

You might also like