diff options
Diffstat (limited to 'selectionsort.go')
| -rw-r--r-- | selectionsort.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/selectionsort.go b/selectionsort.go new file mode 100644 index 0000000..67a33cf --- /dev/null +++ b/selectionsort.go @@ -0,0 +1,23 @@ +package main + +import "fmt" + +var sortingdata []int = []int{1, 23, 4, 234, 123, 4, 4512, 0} + +func selectionSort(in []int) []int { + end := len(in) + for i := 0; i < end; i++ { + min := i + for j := i; j < end; j++ { + if in[j] < in[min] { + min = j + } + } + in[i], in[min] = in[min], in[i] + } + return in +} + +func main() { + fmt.Println(selectionSort(sortingdata)) +} |
