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

Function doSort

sort/circlesort.go:17–44  ·  view source on GitHub ↗

doSort is the recursive function that implements the circle sort algorithm.

(arr []T, left, right int)

Source from the content-addressed store, hash-verified

15
16// doSort is the recursive function that implements the circle sort algorithm.
17func doSort[T constraints.Ordered](arr []T, left, right int) bool {
18 if left == right {
19 return false
20 }
21 swapped := false
22 low := left
23 high := right
24
25 for low < high {
26 if arr[low] > arr[high] {
27 arr[low], arr[high] = arr[high], arr[low]
28 swapped = true
29 }
30 low++
31 high--
32 }
33
34 if low == high && arr[low] > arr[high+1] {
35 arr[low], arr[high+1] = arr[high+1], arr[low]
36 swapped = true
37 }
38
39 mid := left + (right-left)/2
40 leftHalf := doSort(arr, left, mid)
41 rightHalf := doSort(arr, mid+1, right)
42
43 return swapped || leftHalf || rightHalf
44}

Callers 1

CircleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected