Example 1 — Serve customers in order
Numbers are served in the order they joined.
#include <stdio.h>
int main(void) {
int q[5], head = 0, tail = 0;
for (int ticket = 101; ticket <= 103; ticket++) q[tail++] = ticket;
printf("serving:");
while (head < tail) printf(" %d", q[head++]);
printf("\n");
return 0;
} How It Works
- Tickets are enqueued 101, 102, 103.
- Dequeue always reads at
head. - The output order matches the arrival order.
