Skip to content

Latest commit

 

History

History
102 lines (77 loc) · 3.48 KB

File metadata and controls

102 lines (77 loc) · 3.48 KB

Linked List in C

This repository is a collection of small, focused C example programs that demonstrate common linked list operations and algorithms. The files are numbered (01 — 11) and each file implements a self-contained example you can compile and run to learn or test a particular technique.

Table of contents

  • About
  • Repository layout
  • How to build and run
  • File summaries
  • Running the examples (quick start)

About

Each numbered file is an example program that demonstrates one or more linked-list techniques such as insertion, deletion, searching, reversing, sorting, removing duplicates, merging, and a simple performance comparison with arrays.

Repository layout

Files you’ll find in this repo:

  • 01_list.c
  • 02_insert_nodes_into_linkedList.c
  • 03_delete_nodes_from_a_linkedList.c
  • 04_length-search-count_and_replace_operations_for_linkedLists.c
  • 05_delete_matches_from_a_linkedList.c
  • 06_efficiently_delete_all_matches_from_a_linkedList.c
  • 07_appending_and_reversing_linkedLists.c
  • 08_sorting_removing_duplicates_from_a_linkedList.c
  • 09_delete-list_and_insert_after_a_value_in_a_linkedList.c
  • 10_add-List_duplicate-List_merge-sorted-List_Functions.c
  • 11_performance-test_LinkedList_VS_Array.c
  • LinkedList Library/ (directory)

How to build and run

Prerequisites:

  • A C compiler (gcc or clang)
  • POSIX-like shell (optional)

Compile a single example:

# Example: compile and run the first example
gcc -std=c99 -Wall -Wextra 01_list.c -o bin/01_list
./bin/01_list

Compile all examples quickly:

mkdir -p bin
for f in *.c; do
  name=$(basename "$f" .c)
  gcc -std=c99 -Wall -Wextra "$f" -o "bin/$name" || echo "build failed: $f"
done

If you prefer a Makefile, add a simple Makefile to automate the above.

File summaries

A short description of each example:

  • 01_list.c

    • Simple linked list creation and traversal. Demonstrates a small Node struct and a printList function.
  • 02_insert_nodes_into_linkedList.c

    • Examples of inserting nodes into different positions (front, middle, end).
  • 03_delete_nodes_from_a_linkedList.c

    • Deleting nodes by position or value; handling deletion edge-cases (head, single-node lists).
  • 04_length-search-count_and_replace_operations_for_linkedLists.c

    • Length computation, searching for values, counting occurrences, and replacing node values.
  • 05_delete_matches_from_a_linkedList.c

    • Removing nodes that match a condition (single-pass removal, handling head and interior nodes).
  • 06_efficiently_delete_all_matches_from_a_linkedList.c

    • More efficient approaches for removing all matching nodes (minimizing pointer updates).
  • 07_appending_and_reversing_linkedLists.c

    • Appending lists, concatenation, and in-place reversal algorithms.
  • 08_sorting_removing_duplicates_from_a_linkedList.c

    • Sorting (merge sort / other algorithms suitable for linked lists) and duplicate removal techniques.
  • 09_delete-list_and_insert_after_a_value_in_a_linkedList.c

    • Deleting an entire list and inserting after a specific node value.
  • 10_add-List_duplicate-List_merge-sorted-List_Functions.c

    • Utility functions: adding two lists, duplicating a list, merging sorted lists, and helpers.
  • 11_performance-test_LinkedList_VS_Array.c

    • A performance comparison between linked list operations and array operations (benchmark-style).

Running the examples (quick start)

  1. Build: gcc -std=c99 -Wall -Wextra 01_list.c -o bin/01_list

  2. Run: ./bin/01_list