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

Function partition

search/selectk.go:22–32  ·  view source on GitHub ↗
(array []int, l, r int)

Source from the content-addressed store, hash-verified

20}
21
22func partition(array []int, l, r int) int {
23 elem, j := array[l], l+1
24 for i := l + 1; i < r; i++ {
25 if array[i] <= elem {
26 array[i], array[j] = array[j], array[i]
27 j++
28 }
29 }
30 array[l], array[j-1] = array[j-1], array[l]
31 return j - 1
32}

Callers 1

selectKFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected