 cocktail sort, also known as bidirectional bubble sort, cocktail shaker sort, shaker sort (which can also refer to a variant of selection sort), ripple sort, shuffle sort,martin duhl: die schrittweise entwicklung und beschreibung einer shuffle-sort-array schaltung in hyperkarl aus der algorithmischen darstellung des bubble-sort-algorithmus, projektarbeit, 1986, technical university of kaiserslautern or shuttle sort, is a variation of bubble sort that is both a stable sorting algorithm and a comparison sort. the algorithm differs from a bubble sort in that it sorts in both directions on each pass through the list. this sorting algorithm is only marginally more difficult to implement than a bubble sort, and solves the problem of turtles in bubble sorts. it provides only marginal performance improvements, and does not improve asymptotic performance; like the bubble sort, it is not of practical interest (insertion sort is preferred for simple sorts), though it finds some use in education. == pseudocode == the simplest form of cocktail sort goes through the whole list each time: {| style="clear:both" |} procedure cocktailsort( a : list of sortable items ) defined as: do swapped := false for each i in 0 to length( a ) - 2 do: if a[ i ] > a[ i + 1 ] then // test whether the two elements are in the wrong order swap( a[ i ], a[ i + 1 ] ) // let the two elements change places swapped := true end if end for if swapped = false then // we can exit the outer loop here if no swaps occurred. break do-while loop end if swapped := false for each i in length( a ) - 2 to 0 do: if a[ i ] > a[ i + 1 ] then swap( a[ i ], a[ i + 1 ] ) swapped := true end if end for while swapped // if no elements have been swapped, then the list is sorted end procedure the first rightward pass will shift the largest element to its correct place at the end, and the following leftward pass will shift the smallest element to its correct place at the beginning. the second complete pass will shift the second largest and second smallest elements to their correct places, and so on. after i passes, the first i and the last i elements in the list are in their correct positions, and do not need to be checked. by shortening the part of the list that is sorted each time, the number of operations can be halved (see bubble sort). procedure cocktailsort( a : list of sortable items ) defined as: // `begin` and 
Comparison_sorts Sorting_algorithms Stable_sorts