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

Function Bubble

sort/bubblesort.go:9–21  ·  view source on GitHub ↗

Bubble is a simple generic definition of Bubble sort algorithm.

(arr []T)

Source from the content-addressed store, hash-verified

7
8// Bubble is a simple generic definition of Bubble sort algorithm.
9func Bubble[T constraints.Ordered](arr []T) []T {
10 swapped := true
11 for swapped {
12 swapped = false
13 for i := 0; i < len(arr)-1; i++ {
14 if arr[i+1] < arr[i] {
15 arr[i+1], arr[i] = arr[i], arr[i+1]
16 swapped = true
17 }
18 }
19 }
20 return arr
21}

Callers 1

MedianFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected