0% found this document useful (0 votes)
32 views6 pages

Circular Queue Implementation in C

Uploaded by

rmenonharigovind
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)
32 views6 pages

Circular Queue Implementation in C

Uploaded by

rmenonharigovind
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

#include <stdio.

h>

int main()

int size;

printf("Enter size of the circular queue: ");

scanf("%d", &size);

int queue[size];

int front = -1, rear = -1;

int choice, value;

while (1)

printf("\n=========== CIRCULAR QUEUE MENU ===========\n");

printf("1. Enqueue (Insert)\n");

printf("2. Dequeue (Delete)\n");

printf("3. Display Queue\n");

printf("4. Exit\n");

printf("===========================================\n");

printf("Enter your choice: ");

scanf("%d", &choice);

switch (choice)

case 1: // Enqueue

if ((rear + 1) % size == front)

printf("\n⚠️ Queue is FULL! Cannot insert.\n");

}
else

printf("Enter value to enqueue: ");

scanf("%d", &value);

if (front == -1)

front = rear = 0;

else

rear = (rear + 1) % size;

queue[rear] = value;

printf("✅ Inserted %d successfully.\n", value);

break;

case 2: // Dequeue

if (front == -1)

printf("\n⚠️ Queue is EMPTY! Nothing to delete.\n");

else

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

if (front == rear)

// Queue becomes empty


front = rear = -1;

else

front = (front + 1) % size;

break;

case 3: // Display

if (front == -1)

printf("\n⚠️ Queue is EMPTY!\n");

else

printf("\n📜 Queue elements: ");

int i = front;

while (1)

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

if (i == rear)

break;

i = (i + 1) % size;

printf("\n");

break;

case 4: // Exit
printf("\n👋 Exiting program. Thank you!\n");

return 0;

default:

printf("\n❌ Invalid choice! Please try again.\n");

return 0;

You might also like