Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cipepser
Created January 9, 2017 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cipepser/a224fb335644d3ca8567ec6aff87acb7 to your computer and use it in GitHub Desktop.
Save cipepser/a224fb335644d3ca8567ec6aff87acb7 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func Min(a []int) (idx, n int) {
n = a[0]
idx = 0
for i, v := range a {
if n > v {
n = v
idx = i
}
}
return
}
func SelectionSort(a []int) []int {
for i, _ := range a {
idx, _ := Min(a[i:len(a)])
a[i], a[i + idx] = a[i + idx], a[i]
}
return a
}
func main() {
a := []int{2, 4, 5, 1, 3}
fmt.Println(SelectionSort(a))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment