Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Queue Implementations in C

Three different ways to implement a Queue (FIFO) data structure in C, written while studying and preparing to teach the topic.

Files

array_queue.c — Simple Array-Based Queue

The most basic implementation: a fixed-size array with front and rear indices that only move forward.

Demonstrates the false overflow problem — once rear reaches the end of the array, no more elements can be added even if slots at the front have been freed by dequeue().

circular_queue.c — Circular Queue

Fixes the false overflow problem using modular arithmetic: rear = (rear + 1) % CAPACITY.

Once the end of the array is reached, the index wraps back around to 0, so freed slots at the front are reused. Still fixed capacity, but no wasted memory.

linked_list_queue.c — Linked List Queue

Uses dynamically allocated nodes (malloc/free) instead of a fixed-size array.

No capacity limit and no false overflow, at the cost of extra memory per node (a pointer) and the responsibility of managing allocation/deallocation correctly.

Build & Run

Each file is self-contained and can be compiled independently:

gcc -Wall -o array_queue array_queue.c && ./array_queue
gcc -Wall -o circular_queue circular_queue.c && ./circular_queue
gcc -Wall -o linked_list_queue linked_list_queue.c && ./linked_list_queue

Summary

Array (simple) Circular Linked List
enqueue / dequeue O(1) O(1) O(1)
Capacity Fixed Fixed Dynamic
False overflow Yes No No
malloc / free needed No No Yes

About

Three C implementations of the Queue (FIFO) data structure — simple array, circular array, and linked list — demonstrating the false overflow problem and its solutions.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages