MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Comb

Function Comb

sort/combSort.go:20–36  ·  view source on GitHub ↗

Comb is a simple sorting algorithm which is an improvement of the bubble sorting algorithm.

(data []T)

Source from the content-addressed store, hash-verified

18
19// Comb is a simple sorting algorithm which is an improvement of the bubble sorting algorithm.
20func Comb[T constraints.Ordered](data []T) []T {
21 n := len(data)
22 gap := n
23 swapped := true
24
25 for gap != 1 || swapped {
26 gap = getNextGap(gap)
27 swapped = false
28 for i := 0; i < n-gap; i++ {
29 if data[i] > data[i+gap] {
30 data[i], data[i+gap] = data[i+gap], data[i]
31 swapped = true
32 }
33 }
34 }
35 return data
36}

Callers

nothing calls this directly

Calls 1

getNextGapFunction · 0.85

Tested by

no test coverage detected