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

Circular Queue Using Array

The document describes a program to implement a circular queue using an array in C. It defines functions for inserting items into the queue, deleting items from the queue, and displaying the contents of the queue. The queue is implemented using a fixed-size array of size 5, with variables to track the front and rear of the queue. The main function provides a menu to call the insert, delete, display, and exit functions in a loop.

Uploaded by

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

Circular Queue Using Array

The document describes a program to implement a circular queue using an array in C. It defines functions for inserting items into the queue, deleting items from the queue, and displaying the contents of the queue. The queue is implemented using a fixed-size array of size 5, with variables to track the front and rear of the queue. The main function provides a menu to call the insert, delete, display, and exit functions in a loop.

Uploaded by

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

www.eazynotes.com Gursharan Singh Tatla Page No.

CIRCULAR QUEUE USING ARRAY

/**** Program to Implement Circular Queue using Array ****/

#include<stdio.h>

#define SIZE 5

void insert();
void delet();
void display();

int queue[SIZE], rear=-1, front=-1, item;

main()
{
int ch;
do
{
printf("\n\n1.\tInsert\n2.\tDelete\n3.\tDisplay\n4.\tExit\n");
printf("\nEnter your choice: ");
scanf("%d", &ch);

switch(ch)
{
case 1:
insert();
break;

case 2:
delet();
break;

case 3:
display();
break;

case 4:
exit(0);

default:
printf("\n\nInvalid choice. Pleasr try again...\n");
}
} while(1);
getch();
}
www.eazynotes.com Gursharan Singh Tatla Page No. 2

void insert()
{
if((front==0 && rear==SIZE-1) || (front==rear+1))
printf("\n\nQueue is full.");
else
{
printf("\n\nEnter ITEM: ");
scanf("%d", &item);

if(rear == -1)
{
rear = 0;
front = 0;
}
else if(rear == SIZE-1)
rear = 0;
else
rear++;

queue[rear] = item;
printf("\n\nItem inserted: %d\n", item);
}
}

void delet()
{
if(front == -1)
printf("\n\nQueue is empty.\n");
else
{
item = queue[front];

if(front == rear)
{
front = -1;
rear = -1;
}
else if(front == SIZE-1)
front = 0;
else
front++;

printf("\n\nITEM deleted: %d", item);


}
}
www.eazynotes.com Gursharan Singh Tatla Page No. 3

void display()
{
int i;

if((front == -1) || (front==rear+1))


printf("\n\nQueue is empty.\n");
else
{
printf("\n\n");

for(i=front; i<=rear; i++)


printf("\t%d",queue[i]);
}
}

You might also like