Skip to content

m-haisham/sortvis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sortvis

A simple sorting algorithm visualizer written in pygame

Displays number of list accesses and writes

Imgur

Quicksort with 200 randomised starting values

Implemented algorithms

  • Cocktail sort
  • Cycle sort
  • Insertion sort
  • Quick sort

Change current algorithm

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

Want to use your own algorithm?

Use the adapter

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

Why doesnt my function work?

Write your own

Each algorithm should inherit visualizer.sorting.Algorithm with the implementation overriding the method sort

Guideline

  • 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

About

Algorithm visualizer written in pygame

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages