⚠️ This project is under development!
This project provides code examples for various data structures and algorithms in C90 (ANSI C) with a focus on correctness, safety, and simplicity.
File | Data Structure | Description |
---|---|---|
simple_bst.c |
Binary Searcy Tree (BST) | Basic, unbalanced tree |
avl_tree.c |
AVL Tree | Search and Delete operations are unimplemented |
File | Algorithm | Description | Recursive | Buffer-based |
---|---|---|---|---|
merge_sort.c |
Merge Sort | Top-down | Yes | Yes (buffer-based merging) |
tree_sort.c |
Tree Sort | Simple BST | Yes | Yes (BST) |
tree_sort_no_recursion.c |
Tree Sort | Simple BST | No | Yes (BST and stacks) |
Just copy the code into existing code bases and refactor it a bit to fit your preferences. The code is short and doing that should be easy for any programmers.
The sorted element type is int
in the examples, but those can easily be used for any comparable types.
🪟 Windows
In case you need something to run out-of-the-box, you can follow the instruction in this section.
⚠️ This project’s Makefile uses Windows shell commands. It will not work on Unix/Linux/macOS without modification. Efforts for cross-platform compatibility is in progress.
- Install Scoop if you haven't already.
- Install
make
andgcc
:
scoop install make gcc
- Clone this repository and
cd
into it. - Use
make
(see below) to build and run.
To build all sorting executables:
make
Each .c
file in the project will produce a corresponding binary in build/bin/
.
You can run a sorting program like this:
make run NAME=merge_sort ARGS="5 1212 33 3 -1 0"
This runs the compiled binary build/bin/merge_sort
with the following input:
- First argument: number of elements (
5
) - Next arguments: array elements (
1212 33 3 -1 0
)
Output:
-1 0 3 33 1212
To clean all build artifacts:
make clean
This will remove the entire build/
directory, including binaries and object files.
- Ensure portability for Makefile (not just working on Windows)
- Merge Sort
- Tree Sort
- Using simple BST
- Using red-black tree
- Quicksort
- Heap Sort
- Insertion Sort
- Bubble Sort
- Shell Sort
- Unit tests for correctness
- Benchmarking mode
This project is provided under the Creative Commons Zero v1.0 Universal, i.e. this work is under world-wide public domain.