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

Function selectK

search/selectk.go:11–20  ·  view source on GitHub ↗

search the element which index is idx

(array []int, l, r, idx int)

Source from the content-addressed store, hash-verified

9
10// search the element which index is idx
11func selectK(array []int, l, r, idx int) int {
12 index := partition(array, l, r)
13 if index == idx {
14 return array[index]
15 }
16 if index < idx {
17 return selectK(array, index+1, r, idx)
18 }
19 return selectK(array, l, index, idx)
20}
21
22func partition(array []int, l, r int) int {
23 elem, j := array[l], l+1

Callers 1

SelectKFunction · 0.85

Calls 1

partitionFunction · 0.85

Tested by

no test coverage detected