This repository provides a collection of fundamental data structure implementations in C, designed for easy integration and reuse in various projects. It includes commonly used structures such as linked lists, stacks, queues, trees, heaps, and hash tables.
- Hardware: Any machine capable of running C.
- Operating System: Recommended Ubuntu 22.04 or similar Linux distro.
- Software:
git
to clone the repository- Build tools installed from the
setup.sh
-
Clone the repository:
git clone https://github.com/HeapBadger/c-data-structures.git cd c-data-structures/
-
Run the setup script to install dependencies:
chmod +x setup.sh ./setup.sh
- To compile all data structure implementations:
make all
- To clean up build files:
make clean
All data structures include tests in the tests/ directory covering edge cases and correctness.
Run tests with:
./bin/test_main help
./bin/test_main list
./bin/test_main <specific suite name>
help
: Displays a usage guide.list
: Lists all available test suite names.<specific suite name>
: Runs a specific test suite.
Additional Makefile commands:
- Format all code:
make format
- Run all tests under Valgrind to check memory usage:
make valgrind
You can build and use the data structures as a static library (libcds.a
) in your own C projects.
make lib
This generates:
lib/libcds.a # Static library archive
include/*.h # Public headers
- Include headers in your source files:
#include "linked_list.h"
#include "stack.h"
// etc.
- Link against the library when compiling:
gcc your_app.c -I./include -L./lib -lcds -o your_app
your-project/
├── main.c
├── Makefile
└── c-data-structures/ # Submodule or copy of this repo
├── include/
├── lib/
└── libcds.a
c-data-structures/
│
├── include/
│ ├── ...
│
├── src/
│ ├── ✅ linked_list.c
│ ├── ✅ array.c
│ ├── ✅ matrix.c
│ ├── ✅ stack.c
│ ├── ✅ queue.c
│ ├── binary_tree.c
│ ├── binary_heap.c
│ ├── hash_table.c
│ ├── deque.c
│ ├── trie.c
│ ├── disjoint_set.c
│ ├── skip_list.c
│ ├── bloom_filter.c
│
├── tests/
│ ├── ...
│
└── Makefile
└── README.md
└── setup.sh
No known issues.