[go: up one dir, main page]

0% found this document useful (0 votes)
12 views4 pages

Prog 5

The document outlines a C program designed to demonstrate operations on a linear queue using an array. It includes functionalities for inserting, deleting, and displaying elements in the queue. The program features a menu-driven interface for user interaction.

Uploaded by

chandan356112
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)
12 views4 pages

Prog 5

The document outlines a C program designed to demonstrate operations on a linear queue using an array. It includes functionalities for inserting, deleting, and displaying elements in the queue. The program features a menu-driven interface for user interaction.

Uploaded by

chandan356112
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
You are on page 1/ 4

PROGRAM NO.

AIM: Program to demonstrate the implementation of various operations on a linear queue


represented using a linear array.

OBJECTIVE: Develop a C program to perform insertion, deletion on queue and display the
elements of queue.
OUTCOME: Students will understand the use of queue implemented using array.
CODE:
#include <stdio.h>
#define MAX 50
void insert();
void delete();
void display();
int queue_array[MAX], front=rear=-1;
void main()
{
int choice;
while (1)
{
printf("\n\t\t\t *****Queue menu****\n");
printf("1.Insert element to queue \n");
printf("2.Delete element from queue \n");
printf("3.Display all elements of queue \n");
printf("4.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:
printf(“Ex
it point”);
break;
default: printf("Wrong choice \n");
}
}
}
void insert()
{
int add_item;
if(rear==MAX-1)
printf(“Queue overflow”);
else
{
if (front == - 1)
front = 0;
printf("\t\t\tInsert the element in queue : ");
scanf("%d", &add_item);
rear = rear + 1;
queue_array[rear] = add_item;
}
}
void delete()
{
if (front == - 1 || front > rear)
{
printf("Queue Underflow \n");
return ;
}
else
{
printf("\t\t\tElement 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(" \t\t\tQueue is : ");
for (i = front; i <= rear; i++)
printf(“%d”,queue_array[i]);
printf("\n");
}
}

Output:

You might also like