A C-based data structures project implementing stack and queue abstract data types using linked lists, dynamic memory allocation, structs, and pointer manipulation.
The implementation supports inserting, removing, accessing, and managing elements while safely handling memory and error states.
C Stack and Queue Implementation demonstrates how fundamental data structures work internally using low-level programming concepts.
Both the stack (LIFO) and queue (FIFO) are implemented using a shared node structure with void pointers, allowing the structures to store any data type.
Operations manipulate the data structures through pointer traversal and dynamic memory allocation using malloc and free. Each structure also tracks its size and maintains an error code to signal invalid operations.
The project emphasizes:
- Dynamic memory management
- Pointer traversal and manipulation
- Implementation of Stack (LIFO) and Queue (FIFO) behaviors
- Generic data storage using
void* - Modular program structure with header and implementation files
- Safe handling of edge cases (empty structures and allocation failures)
- Initialize a queue structure
- Enqueue elements to the rear of the queue
- Dequeue elements from the front of the queue
- Peek at the front element
- Peek at the rear element
- Check if the queue is empty
- Retrieve the current queue size
- Clear all elements from the queue
- Free all allocated queue memory
- Error code tracking for invalid operations
- Initialize a stack structure
- Push elements onto the top of the stack
- Pop elements from the top of the stack
- Peek at the top element
- Check if the stack is empty
- Retrieve the current stack size
- Free all allocated stack memory
- Error code tracking for invalid operations
gcc main.c stacks-queues.c -o stacksqueues
./stacksqueues