0% found this document useful (0 votes)
5 views3 pages

Circular Queue

This C program implements a circular queue using arrays with a maximum size of 5. It includes functions to check if the queue is full or empty, enqueue and dequeue elements, and display the current elements in the queue. The main function demonstrates the usage of these operations by enqueuing and dequeuing elements.

Uploaded by

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

Circular Queue

This C program implements a circular queue using arrays with a maximum size of 5. It includes functions to check if the queue is full or empty, enqueue and dequeue elements, and display the current elements in the queue. The main function demonstrates the usage of these operations by enqueuing and dequeuing elements.

Uploaded by

sawantlaxmi91
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// C Program to implement the circular queue in c using arrays

#include <stdio.h>

#define N 5

int queue[N];

int front = -1, rear = -1;

// Function to check if the queue is full

int isFull()

// If the next position is the front, the queue is full

return (rear + 1) % N == front;

int isEmpty()

return front == -1;

void enqueue(int data)

if (isFull())

printf("Queue overflow\n");

return;

if (front == -1)

front = 0;

rear = (rear + 1) % N;

queue[rear] = data;
printf("Element %d inserted\n", data);

int dequeue()

if (isEmpty())

printf("Queue underflow\n");

return -1;

int data = queue[front];

if (front == rear) {

front = rear = -1;

Else

front = (front + 1) % N;

return data;

void display()

if (isEmpty())

printf("Queue is empty\n");

return;

printf("Queue elements: ");

int i = front;
while (i != rear)

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

i = (i + 1) % N;

printf("%d\n", queue[rear]);

int main()

enqueue(10);

enqueue(20);

enqueue(30);

display();

printf("Dequeued element: %d\n", dequeue());

display();

return 0;

You might also like