summaryrefslogtreecommitdiff
path: root/sort
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2020-07-17 09:25:59 +0100
committerPaul Buetow <paul@buetow.org>2020-07-17 09:25:59 +0100
commit82a314d3f211f9da4f0a906ccbe2df279c79e6de (patch)
tree13cc7c16cc414deca6ca27044dc81e05ce4a9bf9 /sort
parent224cff0a5113b1ea1a09fd48caf164e5690ec8a7 (diff)
initial shuffle sort
Diffstat (limited to 'sort')
-rw-r--r--sort/shuffle.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/sort/shuffle.go b/sort/shuffle.go
new file mode 100644
index 0000000..040456b
--- /dev/null
+++ b/sort/shuffle.go
@@ -0,0 +1,24 @@
+package sort
+
+import (
+ "algorithms/ds"
+)
+
+func Shuffle(a ds.ArrayList) ds.ArrayList {
+ length := len(a)
+ for i := 0; i < length; i++ {
+ min := i
+ for j := i + 1; j < length; j++ {
+ if a[min].Higher(a[j]) {
+ min = j
+ }
+ }
+ if min == i {
+ continue
+ }
+ tmp := a[i]
+ a[i] = a[min]
+ a[min] = tmp
+ }
+ return a
+}