summaryrefslogtreecommitdiff
path: root/sort
diff options
context:
space:
mode:
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
+}