2
0
mirror of https://github.com/0xAX/go-algorithms synced 2024-11-13 13:10:30 +00:00
go-algorithms/sorting/selection_sort.go

24 lines
417 B
Go

package main
/*
* Selection sort - http://en.wikipedia.org/wiki/Selection_sort
*/
func SelectionSort(arr []int) {
var min int = 0
var tmp int = 0
for i := 0; i < len(arr); i++ {
min = i
for j := i + 1; j < len(arr); j++ {
if arr[j] < arr[min] {
min = j
}
}
tmp = arr[i]
arr[i] = arr[min]
arr[min] = tmp
}
}