/***********************************************************************************/
Name : K. Yedukrishnan Date : 02/11/2023
CIRCULAR QUEUE USING ARRAY
Roll:No : 42 Experiment No : 8
/***********************************************************************************/
PROGRAM
#include<stdio.h>
int a[20],size,front,rear;
void enqueue_cq(int item)
if((rear+1)%size==front)
printf("\nQueue is full.");
else if(rear==-1&&front==-1)
front=rear=0;
a[rear]=item;
else
rear=(rear+1)%size;
a[rear]=item;
void dequeue_cq()
if(rear==-1&&front==-1)
{
printf("\nQueue is empty.");
else if(front==rear)
printf("\nDeleted item is:%d",a[front]);
front=rear=-1;
else
printf("\nDeleted item is:%d",a[front]);
front=(front+1)%size;
void display_cq()
int i;
if(rear==-1&&front==-1)
printf("\nQueue is empty.");
else if(front<=rear)
for(i=front;i<=rear;i++)
printf("\t%d",a[i]);
else
{
for(i=front;i<size;i++)
printf("\t%d",a[i]);
for(i=0;i<=rear;i++)
printf("\t%d",a[i]);
void main()
int opt,item;
front=rear=-1;
printf("\nEnter the size of the queue:");
scanf("%d",&size);
do
printf("\nChoose an operation to perform;\n(1)ENQUEUE\n(2)DEQUEUE\n(3)DISPLAY\n(4)EXIT\n");
scanf("%d",&opt);
switch(opt)
case 1:printf("\nEnter the item to be inserted:");
scanf("%d",&item);
enqueue_cq(item);
break;
case 2:dequeue_cq();
break;
case 3:display_cq();
break;
case 4:break;
default:printf("\nInvalid option.");
}while(opt!=4);
/***********************************************************************************/
OUTPUT
Enter the size of the queue:3
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
Enter the item to be inserted:2
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
Enter the item to be inserted:3
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
1
Enter the item to be inserted:4
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
Enter the item to be inserted:5
Queue is full.
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
2 3 4
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
Deleted item is:2
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
1
Enter the item to be inserted:6
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
3 4 6
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
Deleted item is:3
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
Deleted item is:4
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
Deleted item is:6
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
Queue is empty.
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
Queue is empty.
Choose an operation to perform;
(1)ENQUEUE
(2)DEQUEUE
(3)DISPLAY
(4)EXIT
/***********************************************************************************/