MCPcopy Create free account
hub / github.com/0xAX/go-algorithms / CocktailSort

Function CocktailSort

sorting/cocktail_sort.go:7–33  ·  view source on GitHub ↗

* * Cocktail sort - https://en.wikipedia.org/wiki/Cocktail_sort */

(arr []int)

Source from the content-addressed store, hash-verified

5 */
6
7func CocktailSort(arr []int) {
8 tmp := 0
9
10 for i := 0; i < len(arr)/2; i++ {
11 left := 0
12 right := len(arr) - 1
13
14 for left <= right {
15
16 if arr[left] > arr[left+1] {
17 tmp = arr[left]
18 arr[left] = arr[left+1]
19 arr[left+1] = tmp
20 }
21
22 left++
23
24 if arr[right-1] > arr[right] {
25 tmp = arr[right-1]
26 arr[right-1] = arr[right]
27 arr[right] = tmp
28 }
29
30 right--
31 }
32 }
33}
34

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected