Bidirectional bubble sort
Bidirectional Bubble Sort also known as Cocktail Sort or Shaker
Sort is a variation of Bubble Sort that is both a stable sorting
algorithm and a comparison sort. The algorithm differs from Bubble
Sort in that sorts in both directions each pass through the list. The
average number of comparisons is slightly reduced by this
approach (Donald, 1998). This sorting algorithm is only marginally
more difficult than Bubble Sort to implement, and solves the
problem with so-called turtles in Bubble Sort. Consider the problem
of sorting the same set of numbers used for Bubble Sort: