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

Week11 Assignment CircularQueue

The document describes the implementation of a circular queue in C to address the limitations of linear queues. It includes objectives such as understanding the circular queue concept, optimizing memory usage, and implementing wrap-around logic. The provided C program demonstrates the enqueue, dequeue, and display functions for managing the circular queue.

Uploaded by

rlohith33
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

Week11 Assignment CircularQueue

The document describes the implementation of a circular queue in C to address the limitations of linear queues. It includes objectives such as understanding the circular queue concept, optimizing memory usage, and implementing wrap-around logic. The provided C program demonstrates the enqueue, dequeue, and display functions for managing the circular queue.

Uploaded by

rlohith33
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

ASSIGNMENT: Circular Queue

Implementation
Description
Implement a circular queue to overcome limitations of linear queues.

Objectives
• Understand circular queue concept
• Optimize memory usage
• Implement wrap-around logic

C Program
#include <stdio.h>
#define SIZE 5

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

void enqueue(int value) {


if ((rear + 1) % SIZE == front) {
printf("Queue is Full\n");
return;
}
if (front == -1)
front = 0;

rear = (rear + 1) % SIZE;


queue[rear] = value;
}

void dequeue() {
if (front == -1) {
printf("Queue is Empty\n");
return;
}

printf("Deleted: %d\n", queue[front]);


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

void display() {
if (front == -1) {
printf("Queue is Empty\n");
return;
}

int i = front;
printf("Queue: ");
while (1) {
printf("%d ", queue[i]);
if (i == rear)
break;
i = (i + 1) % SIZE;
}
printf("\n");
}

int main() {
enqueue(10);
enqueue(20);
enqueue(30);
enqueue(40);
enqueue(50);

display();
dequeue();
display();

return 0;
}

Output Screenshot
____________________________

____________________________

____________________________
____________________________

____________________________

You might also like