0% found this document useful (0 votes)
8 views5 pages

Practical 6

The document provides a C program that implements a simple queue with operations for insertion, deletion, and display. It includes a menu-driven interface allowing users to choose operations until they decide to exit. The program handles overflow and underflow conditions and displays the current state of the queue after each operation.

Uploaded by

Neelkumar Kadiya
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)
8 views5 pages

Practical 6

The document provides a C program that implements a simple queue with operations for insertion, deletion, and display. It includes a menu-driven interface allowing users to choose operations until they decide to exit. The program handles overflow and underflow conditions and displays the current state of the queue after each operation.

Uploaded by

Neelkumar Kadiya
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
You are on page 1/ 5

PRACTICAL 6

AIM : Implement the simple queue using C Programming.


#include <stdio.h>
#include<stdlib.h>
void insert();
void delete();
void show();
int queue[5];
int Rear = - 1;
int Front = - 1;
main()
{
int ch;
while (1)
{
printf("1.Insert Operation\n");
printf("2.Delete Operation\n");
printf("3.Display the Queue\n");
printf("4.Exit\n");
printf("Enter your choice of operations : ");
scanf("%d", &ch);
switch (ch)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
show();
break;
case 4:
exit(0);
default:
printf("Incorrect choice \n");
}
}
}

void insert()
{
int item;
if (Rear == 5 - 1)
printf("Overflow \n");
else
{
if (Front == - 1)

Front = 0;
printf("Element to be inserted in the Queue\n : ");
scanf("%d", &item);
Rear = Rear + 1;
queue[Rear] = item;
}
}

void delete()
{
if (Front == - 1 || Front > Rear)
{
printf("Underflow \n");
return ;
}
else
{
printf("Element deleted from the Queue: %d\n", queue[Front]);
Front = Front + 1;
}
}

void show()
{

if (Front == - 1)
printf("Empty Queue \n");
else
{
printf("Queue: \n");
for (int i = Front; i <= Rear; i++)
printf("%d ", queue[i]);
printf("\n");
}
}

Output:
1.Insert Operation
2.Delete Operation
3.Display the Queue
4.Exit
Enter your choice of operations : 1
Element to be inserted in the Queue
: 10
1.Insert Operation
2.Delete Operation
3.Display the Queue
4.Exit
Enter your choice of operations : 1
Element to be inserted in the Queue
: 20
1.Insert Operation
2.Delete Operation
3.Display the Queue
4.Exit
Enter your choice of operations : 1
Element to be inserted in the Queue
: 30
1.Insert Operation
2.Delete Operation
3.Display the Queue
4.Exit
Enter your choice of operations : 3
Queue:
10 20 30
1.Insert Operation
2.Delete Operation
3.Display the Queue
4.Exit
Enter your choice of operations : 2
Element deleted from the Queue: 10
1.Insert Operation
2.Delete Operation
3.Display the Queue
4.Exit
Enter your choice of operations : 3
Queue:
20 30

You might also like