A simple sorting algorithm visualizer written in pygame
Displays number of list accesses and writes
Quicksort with 200 randomised starting values
- Cocktail sort
- Cycle sort
- Insertion sort
- Quick sort
change sorta
variable to another sort as shown in main.py
sorta = CocktailSort(bars.sizes)
# sorta = InsertionSort(bars.sizes)
you can start or stop sort by using button on top-center or by pressing Space
Any inline sort function may be passed to SortAdapter
param func
to create an Algorithm
from visualizer.sorting.algorithms import SortAdapter
sorta = SortAdapter(bars.sizes, func=very_fast_sort)
the function should take one parameter, list of values to be sorted
Each algorithm should inherit visualizer.sorting.Algorithm
with the implementation overriding the method sort
- if you want to swap values, use the built in
CallbackList.swap(l1, l2)
. it would work even if its not used.
Other than that no modifications are required
class Algorithm:
def __init__(self, array: Union[CallbackList, list]):
if type(array) == list:
self.array = CallbackList(lambda _: None, array)
else:
self.array = array
def sort(self):
"""
sort the whole array
"""
raise NotImplementedError