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

6 Lab Prog

The document presents a C program that implements a menu driven circular queue with functions for insertion, deletion, display and handling overflow and underflow. The program is tested by inserting and deleting elements and displaying the queue at various points.
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)
11 views4 pages

6 Lab Prog

The document presents a C program that implements a menu driven circular queue with functions for insertion, deletion, display and handling overflow and underflow. The program is tested by inserting and deleting elements and displaying the queue at various points.
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/ 4

Design, Develop and Implement a menu driven Program in C for the following operations on Circular

QUEUE of Characters (Array Implementation of Queue with maximum size MAX)


a. Insert an Element on to Circular QUEUE
b. Delete an Element from Circular QUEUE
c. Demonstrate Overflow and Underflow situations on Circular QUEUE
d. Display the status of Circular QUEUE
e. Exit
Support the program with appropriate functions for each of the above operations

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define SIZE 3
int q[SIZE], f=0,r = -1, count = 0;
void insert_cq()
{
int item;
if (count == SIZE)
{
printf(" the queue overflow\n"); return;
}
printf("Enter the item for insertion\n");
scanf("%d",&item);r = (r + 1)%SIZE;
q[r] = item;
count++;
}
void delete_cq()
{
if (count == 0)
{
printf("Queue underflow\n"); return;
}
printf("Element deleted is %d ",q[f]);
f = (f + 1) % SIZE;
count--;
}
void display_cq()
{
int i,j =f;
if (count == 0)
{
printf("Queue is empty\n");
return;
}
printf(" The contents of queue are");
for ( i = 1; I <= count; i++)
{
printf("%d ",q[j]);
j = ( j + 1)%SIZE;
}
}
void main()
{
int ch;
for(;;)
{
printf("\n1.insert 2.delete 3.display 4: exit\n");
printf("Enter your choice\n");scanf("%d",&ch);
switch(ch)
{
case 1: insert_cq(); break;
case 2: delete_cq(); break;
case 3: display_cq(); break;
default :printf("invalid choice\n");
exit(0);
}
}
}
Output:-

1.insert 2.delete 3.display 4: exit


Enter your choice
1
Enter the item for insertion
11

1.insert 2.delete 3.display 4: exit


Enter your choice
1
Enter the item for insertion
12

1.insert 2.delete 3.display 4: exit


Enter your choice
1
Enter the item for insertion
13

1.insert 2.delete 3.display 4: exit


Enter your choice
1
the queue overflow

1.insert 2.delete 3.display 4: exit


Enter your choice
3
The contents of queue are11 12 13
1.insert 2.delete 3.display 4: exit
Enter your choice
2
Element deleted is 11
1.insert 2.delete 3.display 4: exit
Enter your choice
3
The contents of queue are12 13
1.insert 2.delete 3.display 4: exit
Enter your choice
1
Enter the item for insertion
14

1.insert 2.delete 3.display 4: exit


Enter your choice
3
The contents of queue are12 13 14
1.insert 2.delete 3.display 4: exit
Enter your choice
2
Element deleted is 12
1.insert 2.delete 3.display 4: exit
Enter your choice
2
Element deleted is 13
1.insert 2.delete 3.display 4: exit
Enter your choice
2
Element deleted is 14
1.insert 2.delete 3.display 4: exit
Enter your choice
2
Queue underflow

1.insert 2.delete 3.display 4: exit


Enter your choice
3
Queue is empty

1.insert 2.delete 3.display 4: exit


Enter your choice

You might also like