#include #include #define MAX 5 // change size if needed typedef struct { int data[MAX]; int front; int rear; int count; } Queue; void initialize(Queue *q) { q->front = 0; q->rear = -1; q->count = 0; } bool isFull(Queue *q) { return q->count == MAX; } bool isEmpty(Queue *q) { return q->count == 0; } void push_back(Queue *q, int value) { if (isFull(q)) { printf("Queue is FULL! Cannot insert %d\n", value); return; } q->rear = (q->rear + 1) % MAX; q->data[q->rear] = value; q->count++; } int pop_front(Queue *q) { if (isEmpty(q)) { printf("Queue is EMPTY! Cannot pop.\n"); return -1; // return invalid value } int removed = q->data[q->front]; q->front = (q->front + 1) % MAX; q->count--; return removed; } int size(Queue *q) { return q->count; } void display(Queue *q) { if (isEmpty(q)) { printf("Queue is EMPTY\n"); return; } printf("Queue: "); int i, index; for (i = 0; i < q->count; i++) { index = (q->front + i) % MAX; printf("%d ", q->data[index]); } printf("\n"); } /* ---------------- DRIVER MAIN ---------------- */ int main() { Queue q; initialize(&q); printf("Pushing 10, 20, 30...\n"); push_back(&q, 10); push_back(&q, 20); push_back(&q, 30); display(&q); printf("\nPop two elements:\n"); printf("Popped: %d\n", pop_front(&q)); printf("Popped: %d\n", pop_front(&q)); display(&q); printf("\nPushing 40, 50, 60...\n"); push_back(&q, 40); push_back(&q, 50); push_back(&q, 60); display(&q); printf("\nQueue size: %d\n", size(&q)); printf("Is full? %s\n", isFull(&q) ? "YES" : "NO"); printf("Is empty? %s\n", isEmpty(&q) ? "YES" : "NO"); printf("\nPopping all elements:\n"); while (!isEmpty(&q)) { printf("Popped: %d\n", pop_front(&q)); } printf("Is queue empty now? %s\n", isEmpty(&q) ? "YES" : "NO"); return 0; }