summaryrefslogtreecommitdiff
path: root/selectionsort.go
diff options
context:
space:
mode:
authorMike Vink <mike1994vink@gmail.com>2023-01-13 09:12:31 +0100
committerMike Vink <mike1994vink@gmail.com>2023-01-13 09:12:31 +0100
commit32856929b76a3a6cf82bc233535826bbde46d2da (patch)
treea32711c9d973f43d3bffb93e9cbfe320da43a2a8 /selectionsort.go
parent611ee045b7e7d3822be021d5ea2cbf77306cb343 (diff)
day15 bad
Diffstat (limited to 'selectionsort.go')
-rw-r--r--selectionsort.go23
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))
+}