A neon-themed, animated sorting algorithm visualizer built with Java Swing. Watch 6 classic sorting algorithms come to life with real-time color feedback, live stats, and smooth animations.
- 6 Sorting Algorithms — Bubble, Selection, Insertion, Merge, Quick, Shell
- Neon Dark Theme — gradient bars with glow effects
- Live Stats — comparisons and swaps update in real time
- Speed Control — drag the slider from slow-motion to blazing fast
- Pause / Resume — freeze mid-sort to study any step
- Asc / Desc Toggle — switch between ascending and descending order
- Sweep Animation — satisfying green wave when sorting completes
sortingvisualizer/
├── SortingVisualizer.java ← Main controller & entry point
├── core/
│ ├── SortContext.java ← Shared state (array, flags, counters)
│ └── AbstractSorter.java ← Base class with visual helper methods
├── algorithms/
│ ├── BubbleSorter.java
│ ├── SelectionSorter.java
│ ├── InsertionSorter.java
│ ├── MergeSorter.java
│ ├── QuickSorter.java
│ └── ShellSorter.java
├── ui/
│ ├── BarPanel.java ← Renders the animated bar chart
│ └── ControlPanel.java ← Buttons, slider, and dropdown
└── utils/
└── Theme.java ← Centralized neon color palette
- Java 17 or higher
javac -d . sortingvisualizer/**/*.java sortingvisualizer/*.javajava sortingvisualizer.SortingVisualizer| Color | Meaning |
|---|---|
| 🔵 Cyan | Unsorted bar |
| 🔴 Pink | Currently being compared or swapped |
| 🟡 Yellow | Pivot element (Quick Sort) |
| 🟢 Green | Sorted / finalized bar |
| Algorithm | Best | Average | Worst | Space |
|---|---|---|---|---|
| Bubble Sort | O(n) | O(n²) | O(n²) | O(1) |
| Selection Sort | O(n²) | O(n²) | O(n²) | O(1) |
| Insertion Sort | O(n) | O(n²) | O(n²) | O(1) |
| Merge Sort | O(n log n) | O(n log n) | O(n log n) | O(n) |
| Quick Sort | O(n log n) | O(n log n) | O(n²) | O(log n) |
| Shell Sort | O(n log n) | O(n log² n) | O(n²) | O(1) |
- Create a new file in
sortingvisualizer/algorithms/ - Extend
AbstractSorterand implementsort()andgetName() - Add an instance to the
sorters[]array inSortingVisualizer.java - Add the name string to
ControlPanel.ALGORITHMS
Example:
package sortingvisualizer.algorithms;
import sortingvisualizer.core.AbstractSorter;
import sortingvisualizer.core.SortContext;
import javax.swing.JPanel;
public class HeapSorter extends AbstractSorter {
public HeapSorter(SortContext ctx, JPanel canvas) {
super(ctx, canvas);
}
@Override
public String getName() { return "Heap Sort"; }
@Override
public void sort() throws InterruptedException {
// your logic here
}
}This project is licensed under the MIT License. See LICENSE.md for details.