A comprehensive C library providing various data structure implementations with generic type support.
- Generic data structures using
void*(type-agnostic) - Memory leak prevention and safety checks
- Consistent API design across all structures
- Support for both static and dynamic library builds
- Ordered & unordered associative containers (map/set/umap/uset)
- Ready-to-ship release layout (
release/include+release/lib)
| Structure | Description | Header |
|---|---|---|
| Singly Linked List | Linear collection with forward traversal | linkedlist.h |
| Doubly Linked List | Bi-directional linear collection | linkedlist.h |
| Stack | LIFO data structure | stack.h |
| Queue | FIFO data structure | queue.h |
| Deque | Double-ended queue | deque.h |
| Binary Tree | Tree with max 2 children per node | binarytree.h |
| Heap | Binary heap (min-heap via comparator) | heap.h |
| Map | Ordered map (BST + comparator) | map.h |
| Set | Ordered set (BST + comparator) | set.h |
| Unordered Map | Hash map | umap.h |
| Unordered Set | Hash set | uset.h |
| Graph | Adjacency-list graph | graph.h |
- Singly Linked List
- Doubly Linked List
- Stack
- Queue
- Deque
- Binary Tree
- Heap
- Map / Set
- Unordered Map / Unordered Set
- Graph
make release
gcc main.c -Irelease/include -Lrelease/lib -lreestruct -o mainPlace the built library (release/lib) alongside your binary or update PATH/LD_LIBRARY_PATH as needed.
bash scripts/build.sh # defaults to release
bash scripts/build.sh static # or shared / all / clean / test / docsOn Windows, run the script from Git Bash/MSYS2/WSL so make is available. The script sets OS for the Makefile automatically.
make test# or
bash scripts/build.sh testRequires doxygen installed:
make docs
# or
bash scripts/build.sh docsOutput: docs/html/index.html.
You can include all structures:
#include"reestruct.h"Atau untuk lebih efisien (khusus kebutuhan):
#include"linkedlist.h"// Only linked list#include"stack.h"// Only stack#include"queue.h"// Only queue#include"deque.h"// Only deque#include"binarytree.h"// Only binary tree#include"stack.h"#include<stdio.h>voidprintInt(void*data) {
printf("%d ", *(int*)data);
}
intmain() {
Stack*stack=createStack();
intnums[] = {1, 2, 3, 4, 5};
for(inti=0; i<5; i++) {
push(stack, &nums[i]);
}
printStack(stack, printInt);
freeStack(stack);
return0;
}#include"map.h"#include<stdio.h>intintCompare(constvoid*a, constvoid*b) {
intda=*(constint*)a;
intdb=*(constint*)b;
return (da>db) - (da<db);
}
voidprintPair(void*key, void*value) {
printf("%d => %s\n", *(int*)key, (char*)value);
}
intmain() {
Map*map=createMap(intCompare);
intkey1=10, key2=5;
mapPut(map, &key1, "ten");
mapPut(map, &key2, "five");
mapTraverseInOrder(map, printPair);
freeMap(map);
}#include"umap.h"#include<string.h>#include<stdio.h>size_tstrHash(constvoid*key) {
// djb2-ishsize_th=5381;
constunsigned char*p= (constunsigned char*)key;
while (*p) h= ((h << 5) +h) +*p++;
returnh;
}
boolstrEq(constvoid*a, constvoid*b) {
returnstrcmp((constchar*)a, (constchar*)b) ==0;
}
intmain() {
UMap*map=createUMap(strHash, strEq);
umapPut(map, "hello", "world");
printf("%s\n", (char*)umapGet(map, "hello"));
freeUMap(map);
}gcc main.c -Irelease/include -Lrelease/lib -lreestruct -o mainWindows:
gcc main.c -Irelease/include -Lrelease/lib -lreestruct -o main.exe
# Make sure reestruct.dll is in the same folder or in PATHLinux:
gcc main.c -Irelease/include -Lrelease/lib -lreestruct -o main
# Ensure libreestruct.so is in LD_LIBRARY_PATH- Download the latest release from the GitHub Releases Page
- Extract the files to your project directory
- Include the appropriate headers in your code
Gunakan Makefile yang disediakan:
# Build both static and shared libraries
make all
# Build only static library (.a)
make static
# Build only shared library (.dll/.so)
make shared
# Generate release folder
make release
# Clean build files
make cleanrelease/
├── include/
│ ├── reestruct.h
│ ├── stack.h
│ ├── queue.h
│ ├── linkedlist.h
│ └── ...
└── lib/
├── libreestruct.a
└── reestruct.dll / libreestruct.so
Contributions are welcome! Please feel free to submit pull requests.
This project is licensed under the MIT License.
riefproject – Author & Maintainer