MCPcopy Create free account
hub / github.com/0xAX/go-algorithms / SelectionSort

Function SelectionSort

sorting/selection_sort.go:7–23  ·  view source on GitHub ↗

* * Selection sort - http://en.wikipedia.org/wiki/Selection_sort */

(arr []int)

Source from the content-addressed store, hash-verified

5 */
6
7func SelectionSort(arr []int) {
8 var min int = 0
9 var tmp int = 0
10
11 for i := 0; i < len(arr); i++ {
12 min = i
13 for j := i + 1; j < len(arr); j++ {
14 if arr[j] < arr[min] {
15 min = j
16 }
17 }
18
19 tmp = arr[i]
20 arr[i] = arr[min]
21 arr[min] = tmp
22 }
23}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected