Collection of 45 sorting algorithms in Javascript with commentaries. It contains 45 sorting algorithms organised as a library which can be used in Node.js and in browser.
var arr = [98, 45, 101, 0, 7];
arr = Sorting.bubbleSort(arr);
// [0, 7, 45, 98, 101]
Few tests are included (those are non-enumerable)
/**
* Performs a given amount of tests using arrays of random numbers.
* It uses same array of integers for each test.
* Results are displayed in the console using console.table.
* @param {number} l - The length of the each array for sorting. The default value is 1000.
* @param {number} tests - The number of tests to perform. The default value is 1.
*/
Sorting.test();
/**
* Performs a test of a given sorting function using an array of random numbers.
* @param {Function} func - A sorting function. If not provided, the Sorting.quickSort is used.
* @param {number} l - The length of the array. The default value is 5000.
*/
Sorting.testNumbers(func, l);
/**
* Performs a test of a given sorting function using an array of random strings.
* @param {Function} func - A sorting function. If not provided, the Sorting.radixMSDSort is used.
* @param {number} l - The length of the array. The default value is 5000.
*/
Sorting.testStrings(func, l);
- Quicksort.
- Quicksort with 3-way Dijkstra partitioning.
- Dual-pivot Quicksort suggested by V. Yaroslavskiy in 2009.
- Introsort
- Mergesort.
- In-place Mergesort.
- Blocksort.
- Timsort.
- Bucket sort (naive implementation).
- Pigeonhole sort.
- Proxmap sort.
- Spreadsort.
- Flashsort.
- Binary tree sort (simple).
- Red-Black tree sort.
- Splaysort.
- Heap sort.
- Smoothsort.
- JSort.
- Cartesian sort.
- Tournament sort.
- Patience sort.
- Library sort.
- Shell sort.
- Comb sort.
- LSD radix sort.
- MSD radix sort.
- MSD radix quicksort.
- American flag sort.
- Counting sort.
- Bitonic sort.
- Insertion sort.
- Insertion sort with binary search.
- Selection sort.
- Bingo sort.
- Double selection sort.
- Cocktail shaker sort.
- Odd-even sort.
- Bubble sort.
- Cycle sort.
- Gnome sort.
- Pancake sort.
- Quadratic counting sort.
- Bead sort (Gravity sort).
- Stooge sort.