OPTIMIZED-COCKTAIL-SORT.JS


comparisons:
swaps:



Because the lightest elements are floated to the top, and the heaviest elements are sunk to the bottom, cocktail sort creates a sorted sub-array at the beginning of the array, and another one at the end. This algorithm keeps track of the size of these two arrays, and uses that to only scan the unsorted elements in between.

sort.js
bubble-sort.js optimized-bubble-sort.js selection-sort.js
cocktail-sort.js optimized-cocktail-sort.js
odd-even-sort.js comb-sort.js quick-sort.js
gnome-sort.js optimized-gnome-sort.js
compare sort algorithms