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

Circular Queue

The document contains a C program that implements a circular queue using an array. It includes functions for enqueueing, dequeueing, and displaying elements in the queue, along with handling cases for full and empty queues. The main function demonstrates the usage of these queue operations with a predefined size.
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)
3 views2 pages

Circular Queue

The document contains a C program that implements a circular queue using an array. It includes functions for enqueueing, dequeueing, and displaying elements in the queue, along with handling cases for full and empty queues. The main function demonstrates the usage of these queue operations with a predefined size.
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
You are on page 1/ 2

#include<stdio.

h>
#include<stdlib.h>
int arr[100];
int front=-1,rear=-1;
int *size=NULL;
void enqueue(int item){
if (front==(rear+1)%*size){
printf("queue is full\n");
return;
}
if ((front==-1)&&(rear==-1)){
front++;
}
rear=(rear+1)%*size;
arr[rear]=item;
}
void dequeue(){
if (front==-1 && rear==-1){
printf("queue is empty");
return;
}
int x=arr[front];
printf("%d is deleted\n",x);
if (front==rear){
front=rear=-1;
return;
}
front=(front+1)%*size;
}
void display(){
if (front==-1){
printf("queueu is empty\n");
return;
}
int i;
for( i=front;i!=rear;i=(i+1)%*size){
printf("%d ",arr[i]);
}
printf("%d ",arr[i]);
printf("\n");
}
int main()
{ int n=3;
size=&n;
enqueue(6);
display();
enqueue(7);
enqueue(8);
enqueue(6);
display();
dequeue();
display();
enqueue(0);
display();
dequeue();
dequeue();
display();
dequeue();
display();
dequeue();
return 0;
}

You might also like