Small C implementations of classic data structures, built with dynamically allocated linked nodes.
| File | Description |
|---|---|
linkedlist.c |
A singly linked list supporting insertion (front, end, before/after a reference value, sorted), search, removal, sorting, reversal, and concatenating two lists. |
queue.c |
A FIFO queue (enqueue/dequeue) built on a linked list with front/rear pointers and O(1) operations. |
stack.c |
A LIFO stack (push/pop) built on a linked list. |
min_heap.c |
A priority queue (Min-Heap) flat array implementation guaranteeing O(log n) insertions and O(1) extractions. |
Each file is self-contained and includes its own main() with example usage.
Key operations:
create_node,add_node_at_the_front,add_node_at_the_endadd_node_before_ref/add_node_after_ref— insert relative to a value already in the listadd_node_sorted,create_sorted_list,sort_list— keep or make the list sortedfind_node,get_length,print_listremove_node,modify_nodereverse_listconcatenate_lists— join two lists at a given positionfree_list— releases all nodes and prints a message per deallocation
create_queue/free_queueenqueue— adds to the reardequeue— removes from the frontpeek,isEmpty
create_node/free_stackpush— adds to the toppop— removes from the topisEmpty
create_heap/free_heappush— adds a number according to the min-heap principle (each parent node is smaller or equal than its child nodes)pop— removes the smallest number from the heap
Each file can be compiled and run independently:
gcc -o linkedlist linkedlist.c && ./linkedlist
gcc -o queue queue.c && ./queue
gcc -o stack stack.c && ./stack- All structures use dynamic memory allocation (
malloc/free) rather than fixed-size arrays. queue.candstack.cinclude basic checks for allocation failure and empty-structure errors.