Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sorting Algorithm Visualizer

A C++/CLI WinForms desktop application that provides a real-time visual representation of common sorting algorithms using raylib for rendering.

Overview

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.

Supported Algorithms

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)

Project Structure

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

Architecture

MainForm (UI Layer)

  • 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)

Visualizer (Rendering & Logic Layer)

  • 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

Pillar (Data Model)

  • Simple data class holding number, width, and height
  • Height is proportional to the pillar's number value

Algorithm Implementations

Bubble Sort

Repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order.

Insertion Sort

Builds the sorted array one item at a time by inserting each element into its correct position.

Selection Sort

Divides the input into sorted and unsorted regions, repeatedly selecting the smallest element from the unsorted region.

Quick Sort

Divides the array using a pivot element, recursively sorting the sub-arrays. Uses Lomuto partition scheme.

Merge Sort

Divides the array in half, recursively sorts both halves, then merges them back together.

Building the Project

Prerequisites

  • Visual Studio 2019/2022 with C++/CLI support
  • raylib (included via header-only #include <raylib.h>)
  • Windows SDK

Build Steps

  1. Open SortingAlgo.sln in Visual Studio
  2. Set TestingWithNetFramework as the startup project
  3. Build and run (F5)

Usage

  1. Launch the application — a dark-themed panel appears with five algorithm buttons
  2. Click an algorithm button (Bubble Sort, Insertion Sort, Selection Sort, Quick Sort, or Merge Sort) — the selected button turns green
  3. Click "Start Visualizer" to launch the visualization window
  4. Watch the pillars animate as the chosen algorithm sorts them
  5. Close the visualization window to return to the algorithm selection panel

Technical Details

  • Rendering: raylib 2D rendering with DrawRectangle for 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

Demo Videos

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).

Educational Purpose

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages