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

Circular Queue Using Array

This document contains code for implementing a circular queue using an array in C programming language. It defines functions for inserting an item into the queue, deleting an item from the queue, and displaying the items currently in the queue. The code uses global variables to track the front and rear indexes of the queue in the fixed size array as items are added and removed.

Uploaded by

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

Circular Queue Using Array

This document contains code for implementing a circular queue using an array in C programming language. It defines functions for inserting an item into the queue, deleting an item from the queue, and displaying the items currently in the queue. The code uses global variables to track the front and rear indexes of the queue in the fixed size array as items are added and removed.

Uploaded by

saimanobhiram
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. 1

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

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);
}
}

Page No. 2

www.eazynotes.com

void
{

Gursharan Singh Tatla

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]);
}

Page No. 3

You might also like