MCPcopy Create free account
hub / github.com/arnauddri/algorithms / sort

Function sort

algorithms/sorting/bubble-sort/bubble.go:8–21  ·  view source on GitHub ↗
(arr []int)

Source from the content-addressed store, hash-verified

6)
7
8func sort(arr []int) {
9 for itemCount := len(arr) - 1; ; itemCount-- {
10 swap := false
11 for i := 1; i <= itemCount; i++ {
12 if arr[i-1] > arr[i] {
13 arr[i-1], arr[i] = arr[i], arr[i-1]
14 swap = true
15 }
16 }
17 if swap == false {
18 break
19 }
20 }
21}

Callers 2

TestBubbleSortFunction · 0.70
benchmarkBubbleSortFunction · 0.70

Calls

no outgoing calls

Tested by 2

TestBubbleSortFunction · 0.56
benchmarkBubbleSortFunction · 0.56