0% found this document useful (0 votes)
9 views2 pages

Circular Queue Implementation

The document defines a circular queue (CQUEUE) structure in C with functions to check if it is full or empty, insert elements, remove elements, and display the queue contents. It includes a main function that demonstrates the usage of these functions. The queue has a maximum size defined by MAXCQSIZE, and operations are performed using modular arithmetic to manage the circular nature of the queue.

Uploaded by

akshathashetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Circular Queue Implementation

The document defines a circular queue (CQUEUE) structure in C with functions to check if it is full or empty, insert elements, remove elements, and display the queue contents. It includes a main function that demonstrates the usage of these functions. The queue has a maximum size defined by MAXCQSIZE, and operations are performed using modular arithmetic to manage the circular nature of the queue.

Uploaded by

akshathashetty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#define MAXCQSIZE 10

struct CQUEUE
{
int front, rear;
int items[MAXCQSIZE];
};
int iscqueuefull(struct CQUEUE *p)
{
if(p->front==(p->rear+1)%MAXCQSIZE)
return 1;
return 0;
}

void insertcqueue(struct CQUEUE *p, int ele)


{
p->rear=(p->rear+1)%MAXCQSIZE;
p->items[p->rear]=ele;
}

int iscqueueempty(struct CQUEUE *p)


{
if(p->rear==p->front)
return 1;
return 0;
}

int removecq(struct CQUEUE *p)


{
int ele;
p->front=(p->front+1)%MAXCQSIZE;
ele=p->items[p->front];
return ele;
}

void displaycq(struct CQUEUE *p)


{
int i;
if(iscqueueempty(p)){
printf("empty");
return;
}

i=(p->front+1)%MAXCQSIZE;
do
{
printf("%d", p->items[i]);
i=(i+1)%MAXCQSIZE;
}while(i!=p->rear);

main()
{
struct CQUEUE cq;
cq.front=cq.rear=MAXCQSIZE-1;
if (iscqueuefull(&cq))
printf("FULL");
else
insertcqueue(&cq, 100);

if(iscqueueempty(&cq))
printf("EMPTY");
else
{
ele=removecq(&cq);
printf("%d", ele);
}

You might also like