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

Function Partition

sort/quicksort.go:15–26  ·  view source on GitHub ↗
(arr []T, low, high int)

Source from the content-addressed store, hash-verified

13import "github.com/TheAlgorithms/Go/constraints"
14
15func Partition[T constraints.Ordered](arr []T, low, high int) int {
16 index := low - 1
17 pivotElement := arr[high]
18 for i := low; i < high; i++ {
19 if arr[i] <= pivotElement {
20 index += 1
21 arr[index], arr[i] = arr[i], arr[index]
22 }
23 }
24 arr[index+1], arr[high] = arr[high], arr[index+1]
25 return index + 1
26}
27
28// QuicksortRange Sorts the specified range within the array
29func QuicksortRange[T constraints.Ordered](arr []T, low, high int) {

Callers 2

kthNumberFunction · 0.92
QuicksortRangeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected