0% found this document useful (0 votes)
2 views

Program 5

The document provides a C program that implements a queue using an array with defined operations such as insert, delete, and display. It includes a menu-driven interface for user interaction and handles cases for queue overflow and underflow. The program utilizes a fixed maximum size for the queue and manages the front and rear indices accordingly.

Uploaded by

venkatesh cns
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Program 5

The document provides a C program that implements a queue using an array with defined operations such as insert, delete, and display. It includes a menu-driven interface for user interaction and handles cases for queue overflow and underflow. The program utilizes a fixed maximum size for the queue and manages the front and rear indices accordingly.

Uploaded by

venkatesh cns
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Aim

Write a program to implement Queue using array.

Program:
#include <stdio.h>
#include<stdlib.h>
#define MAX 50
void insert();
void delete();
void display();
intqueue_array[MAX];
int rear = - 1;
int front = - 1;
voidmain()
{
int choice;
while (1)
{
printf("QUEUE OPERATIONS");

printf("\n 1.Insert element to queue \n2.Delete element from queue \n3.Display elements of
queue \n4.Quit \n");
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");
}} }
void insert()
{
int element;
if (rear == MAX - 1)
printf("Queue Overflow \n");
else
{

if (front == - 1)
/*If queue is initially empty */
front = 0;
printf("Inset the element in queue : ");
scanf("%d", &element);
rear = rear + 1;
queue_array[rear] = element;
} } /* End of insert() */
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;
} } /* End of delete() */
void display()
{
inti;
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