JavaScript is required for this website. Please allow JavaScript and refresh the page.
home Home
sort Sorts
LOGARITHMIC
Quick Sort Merge Sort Heap Sort
QUADRATIC
Bubble Sort Selection Sort Insertion Sort Gnome Sort Shaker Sort Odd Even Sort Pancake Sort
WEIRD
Bitonic Sort Radix Sort Shell Sort Comb Sort Bogo Sort Stooge Sort
CUSTOM
Your Sort
SORT VISUALIZER

API Documentation

In the Custom Sort page, it's possible to implement a custom sort algorithm and visualize it using the following APIs.


REQUIREMENTS

  • The code must be written using the JavaScript programming language and will get injected and executed in your browser.

  • The main function must be asyncronous and it must accept one positional argument, representing an Array of DOM element objects.
    It must sort the array in-place and return undefined.
    If your function needs more parameters, create another function and use the main one as a wrapper to start the algorithm.

  • The code mustn't use any kind of imports from external modules.

  • The code can contain multiple functions and classes declarations.

  • You must specify the algorithm's entry point (the main function) in the apposite text field.

VISUALIZATION FUNCTIONS

You can use the following functions to visualize the sorting algorithm. Asyncronous functions must be called using the await keyword.

  • getValue(element)

    Returns the numerical value associated with the DOM object, given its index or the object.

    Parameters: element : Number or DOM element
    Returns: Number : Value of the DOM element


  • await updateBox(elements, [index1], [index2], [index3])

    Updates the visualization of the algorithm. Temporarily changes the color of the DOM elements to red, green and blue respectively given their indexes and plays sounds if any index is specified. Call this function after every update to the elements array.

    Parameters: elements : Array of DOM elements
    index1 : Number
    index2 : Number
    index3 : Number

    Returns: undefined


  • await swap(index1, index2)

    Swaps two DOM elements given their indices, with visualization. No need to call await updateBox after.

    Parameters: index1 : Number
    index2 : Number

    Returns: undefined