2014-06-21 17:06:17 +00:00
|
|
|
package main
|
|
|
|
|
2014-06-22 15:00:00 +00:00
|
|
|
/*
|
|
|
|
* Selection sort - http://en.wikipedia.org/wiki/Selection_sort
|
|
|
|
*/
|
|
|
|
|
2014-06-21 17:06:17 +00:00
|
|
|
import "fmt"
|
|
|
|
|
2014-06-24 15:10:09 +00:00
|
|
|
import "github.com/0xAX/go-algorithms"
|
2014-06-22 15:00:00 +00:00
|
|
|
|
2014-06-21 17:06:17 +00:00
|
|
|
func main() {
|
2014-06-22 15:00:00 +00:00
|
|
|
arr := utils.RandArray(10)
|
|
|
|
fmt.Println("Initial array is:", arr)
|
|
|
|
fmt.Println("")
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println("Sorted array: ", arr)
|
2014-06-21 17:06:17 +00:00
|
|
|
}
|