summaryrefslogtreecommitdiff
path: root/scratchdir/selectionsort.go
diff options
context:
space:
mode:
Diffstat (limited to 'scratchdir/selectionsort.go')
-rw-r--r--scratchdir/selectionsort.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/scratchdir/selectionsort.go b/scratchdir/selectionsort.go
new file mode 100644
index 0000000..67a33cf
--- /dev/null
+++ b/scratchdir/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))
+}