Skip to content

Ashutosh-Narvekar10/SortingVisualiser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

⚡ Sorting Visualizer

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.


🎬 Features

  • 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

🗂️ Project Structure

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

🚀 How to Run

Requirements

  • Java 17 or higher

Compile

javac -d . sortingvisualizer/**/*.java sortingvisualizer/*.java

Run

java sortingvisualizer.SortingVisualizer

🎨 Color Guide

Color Meaning
🔵 Cyan Unsorted bar
🔴 Pink Currently being compared or swapped
🟡 Yellow Pivot element (Quick Sort)
🟢 Green Sorted / finalized bar

📊 Algorithm Complexity

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)

🧩 Adding a New Algorithm

  1. Create a new file in sortingvisualizer/algorithms/
  2. Extend AbstractSorter and implement sort() and getName()
  3. Add an instance to the sorters[] array in SortingVisualizer.java
  4. 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
    }
}

📄 License

This project is licensed under the MIT License. See LICENSE.md for details.

About

⚡ Animated sorting algorithm visualizer built with Java Swing — featuring 6 algorithms, neon dark theme, live stats, speed control and asc/desc toggle.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Java 100.0%