Interactive sorting algorithm visualizer written in C using SDL2 library, with:
- multiple sorting algorithms (visual + pure, testable)
- automated tests for algorithm correctness
- Docker image for reproducible builds
- Jenkins CI pipeline that builds the Docker image and runs tests periodically
Implemented sorting algorithms (visualized with SDL2):
- Bubble Sort
- Quick Sort
- Inseration Sort
- Merge Sort
- Heap Sort
For each algorithm, the app:
- generates a random array
- visualizes the sorting process with colored bars
- displays algorithm name and time/space complexity using a pixel font
The project separates visual and pure implementations of the algorithms:
src/sorts.c- visual versionssrc/sorts_pure.c- pure C versions
This separation allows:
- interactive visualization for learning/entertainment purposes
- deterministic, fast tests in CI (no graphics involved)
File: src/tests.c
- generates random arrays
- runs each pure sorting algorithm
- verifies the result is sorted
Tested on Linux Fedora
Prerequisites:
gccmakeSDL2SDL2_ttf
Fedora example:
sudo dnf install gcc make SDL2-devel SDL2_ttf-devel
Build:
make
This produces:
sorting_visualizer- SDL2 GUI applicationtests- pure C test binary
Run visualizer:
./sorting_visualizer
From there:
- choose the algorithm in the terminal menu
- watch sorting process animate in the SDL window
Run tests:
./tests
The Dockerfile turns this project into a reproducible CI-friendly unit. Key points:
- Base image:
debian:stable-slim - Installs:
- build tools(
build-essential) libsdl2-devlibsdl2-ttf-dev
- build tools(
- Sets
WORKDIR /app - Copies the entire repo into the image:
COPY . /app
- Runs:
RUN makeCMD ["./tests"]
So the image build compiles the visualizer and tests using the project's Makefile, and runs the tests inside the container.
Build image:
docker build -t sorting-visualizer-ci .
Run tests in the container:
docker run --rm sorting-visualizer-ci
This is exacly what Jenkins does as part of the CI pipeline.
Jenkins is used (for fun, with a practice purpose) as a CI automation server to:
- Monitor the Git repository for changes
- Build the Docker image for this project
- Run the test suite inside the Docker container
- Mark the pipeline as SUCCESS or FAILURE based on the tests results.
The CI pipeline is defined as code in Jenkinsfile.
What it does:
- Jenkins always uses the same Dockerfile and Makefile as we do locally
- If the tests fail inside Docker, the Jenkins builds fail too
I know there are 2 typical ways to trigger Jenkins when code changes:
- Webhooks (push-based, ideal for hosted Jenkins) The Jenkinsfile in this project can be used this way too, but here, Jenkins runs just locally.
- Poll SCM (current setup, for local Jenkins) Jenkins is running locally, for practicing purposes, and it is not exposed on a public URL. GitHub cannot directly reach Jenkins for webhooks. Instead, Jenkins is configured with Poll SCM:
- automatically and periodically check the Git repository for new commits
- if there is a new commit, it runs the same pipeline described above, (in the dates of 1, 11 and 21th of every month, basically every ~10 days)