#include <stdio.
h>
#define MAX 5 // Maximum queue size
int Queue[MAX]; // Array to store queue elements
int Front = -1, Rear = -1; // Initialize front and rear
// Function to insert an element in the queue (Enqueue)
void Enqueue(int value)
if (Rear == MAX - 1 ) // To check if the queue is full
printf("Queue is Full! Cannot Enqueue %d\n", value);
return;
else if (Front == -1 && Rear == -1)
Front = Rear = 0; // Set front to 0 if queue was empty
Queue[Rear] = value; // Insert value at rear
printf("Enqueued: %d\n", value);
else
Rear ++ ;
Queue[Rear] = value; // Insert value at rear
printf("Enqueued: %d\n", value);
// Function to remove an element from the queue (Dequeue)
int Dequeue()
if (Rear == -1 && Front == -1)
{
printf("Queue is Empty! Cannot Dequeue\n");
return -1;
int value = Queue[Front];
if (Front == Rear)
// If only one element was present
Front = Rear = -1;
else
Front++;
printf("Dequeued: %d\n", value);
return value;
// Function to display queue elements
void Display()
if (Front == -1 && Rear == -1)
printf("Queue is Empty!\n");
return;
printf("Queue elements: ");
for (int i = Front; i <= Rear; i++) {
printf("%d ", Queue[i]);
printf("\n");
// Main function to test the queue
int main()
Enqueue(10);
Enqueue(20);
Enqueue(30);
Display(); // 10 20 30
Dequeue();
Display(); // 20 30
Enqueue(40);
Enqueue(50);
Enqueue(60); // Queue is full
Display(); // 20 30 40 50
return 0;