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

Function innerStooge

sort/stooge_sort.go:15–26  ·  view source on GitHub ↗
(arr []T, i int32, j int32)

Source from the content-addressed store, hash-verified

13)
14
15func innerStooge[T constraints.Ordered](arr []T, i int32, j int32) []T {
16 if arr[i] > arr[j] {
17 arr[i], arr[j] = arr[j], arr[i]
18 }
19 if (j - i + 1) > 2 {
20 t := int32(math.Floor(float64(j-i+1) / 3.0))
21 arr = innerStooge(arr, i, j-t)
22 arr = innerStooge(arr, i+t, j)
23 arr = innerStooge(arr, i, j-t)
24 }
25 return arr
26}
27
28func Stooge[T constraints.Ordered](arr []T) []T {
29 if len(arr) == 0 {

Callers 1

StoogeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected