A C++/CLI WinForms desktop application that provides a real-time visual representation of common sorting algorithms using raylib for rendering.
This project demonstrates how sorting algorithms work through animated visualizations. Each algorithm sorts an array of pillars (bars) with different heights, making it easy to see how elements move and compare during the sorting process.
| Algorithm | Time Complexity (Average) | Space Complexity |
|---|---|---|
| Bubble Sort | O(n²) | O(1) |
| Insertion Sort | O(n²) | O(1) |
| Selection Sort | O(n²) | O(1) |
| Quick Sort | O(n log n) | O(log n) |
| Merge Sort | O(n log n) | O(n) |
SortingAlgorithmVisualizer/
├── TestingWithNetFramework/
│ ├── MainForm.h # WinForms UI — algorithm selection panel
│ ├── MainForm.cpp # Event handlers for UI interactions
│ ├── MainForm.resx # WinForms resource file
│ ├── Visualizer.h # Core visualization logic and sorting algorithms
│ ├── Pillar.h # Pillar class (number, width, height)
│ └── TestingWithNetFramework.vcxproj # Visual Studio C++ project file
├── SortingAlgo.sln # Visual Studio solution file
└── README.md
- WinForms-based graphical user interface
- Algorithm selection buttons (one per algorithm)
- "Start Visualizer" button launches the raylib rendering window
- Visual feedback shows which algorithm is currently selected (button turns green)
- Uses raylib for 2D rendering
- Manages the pillar array (200 pillars by default)
- Implements all five sorting algorithms with per-step rendering
- Renders the current state after every swap operation
- Simple data class holding
number,width, andheight - Height is proportional to the pillar's number value
Repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.
Builds the sorted array one item at a time by inserting each element into its correct position.
Divides the input into sorted and unsorted regions, repeatedly selecting the smallest element from the unsorted region.
Divides the array using a pivot element, recursively sorting the sub-arrays. Uses Lomuto partition scheme.
Divides the array in half, recursively sorts both halves, then merges them back together.
- Visual Studio 2019/2022 with C++/CLI support
- raylib (included via header-only
#include <raylib.h>) - Windows SDK
- Open
SortingAlgo.slnin Visual Studio - Set
TestingWithNetFrameworkas the startup project - Build and run (F5)
- Launch the application — a dark-themed panel appears with five algorithm buttons
- Click an algorithm button (Bubble Sort, Insertion Sort, Selection Sort, Quick Sort, or Merge Sort) — the selected button turns green
- Click "Start Visualizer" to launch the visualization window
- Watch the pillars animate as the chosen algorithm sorts them
- Close the visualization window to return to the algorithm selection panel
- Rendering: raylib 2D rendering with
DrawRectanglefor pillars - Animation: Frame-by-frame rendering after each swap operation
- Window Size: 1250×800 pixels
- Pillar Count: 200 pillars (configurable in
StartVisualizer) - FPS Counter: Displayed in the top-right corner during visualization
- Color Scheme: White pillars on a black background with a cyan UI
The Video Clips/ directory contains recorded demonstrations of each algorithm:
| Algorithm | Video File |
|---|---|
| Bubble Sort | Video Clips/Bubble Sort.mp4 |
| Insertion Sort | Video Clips/Insertion Sort.mp4 |
| Selection Sort | Video Clips/Selection Sort.mp4 |
| Quick Sort | Video Clips/Quick Sort.mp4 |
| Merge Sort | Video Clips/Merge Sort.mp4 |
To view a video, open the corresponding .mp4 file in any video player (e.g., VLC, Windows Media Player, or mpv).
This tool is designed to help students understand how sorting algorithms work by watching them execute step-by-step. It is particularly useful for visual learners who benefit from seeing data structures change in real time.