Comb is a simple sorting algorithm which is an improvement of the bubble sorting algorithm.
(data []T)
| 18 | |
| 19 | // Comb is a simple sorting algorithm which is an improvement of the bubble sorting algorithm. |
| 20 | func 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 | } |
nothing calls this directly
no test coverage detected