A graphical demonstration of the Selection Sort algorithm using graphics.h
in C++.
Input Visualization:
Unsorted Array
Output Visualization:
Sorted Array
This project visualizes how Selection Sort works by drawing vertical lines to represent array elements and highlighting transitions in color:
- White lines: array elements (height = value)
- Green lines: currently selected minimum element
- Real-time swapping animations using
swap_colors()
function
Selection Sort repeatedly:
- Finds the minimum element in the unsorted section
- Swaps it with the first unsorted element
- Updates the visualization on every change
- C++
- graphics.h (Turbo C++ or WinBGIm)
- Install Turbo C++ or any
graphics.h
compatible environment (like WinBGIm) - Compile using:
g++ selection_sort.cpp -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
This version visualizes Selection Sort using Python and matplotlib
. It dynamically updates the bar chart after each swap for a clear view of sorting progress.
Install dependencies with:
pip install matplotlib