summaryrefslogtreecommitdiff
path: root/strandsort.hs
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2015-10-15 21:18:48 +1100
committerJed Barber <jjbarber@y7mail.com>2015-10-15 21:18:48 +1100
commita7a0c2924c68c7dc457debb60f44bffc4aa80682 (patch)
tree9856d3765a3c0929624e4a397e0eec61dee45a04 /strandsort.hs
parent3e30658ec5ca3ade4f9295129729127a30b4addf (diff)
Added cocktail, insertion, strand sorts
Diffstat (limited to 'strandsort.hs')
-rw-r--r--strandsort.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/strandsort.hs b/strandsort.hs
new file mode 100644
index 0000000..8226b79
--- /dev/null
+++ b/strandsort.hs
@@ -0,0 +1,25 @@
+
+
+
+strandSort :: Ord a => [a] -> [a]
+strandSort list = doStrandSort list [] [] []
+
+
+
+doStrandSort :: Ord a => [a] -> [a] -> [a] -> [a] -> [a]
+doStrandSort [] [] [] result = result
+doStrandSort [] sublist unsorted result = doStrandSort unsorted [] [] (merge (reverse sublist) result)
+doStrandSort input [] unsorted result = doStrandSort (tail input) [head input] unsorted result
+doStrandSort input sublist unsorted result =
+ if (head input) >= (head sublist)
+ then doStrandSort (tail input) ((head input):sublist) unsorted result
+ else doStrandSort (tail input) sublist ((head input):unsorted) result
+
+
+
+merge :: Ord a => [a] -> [a] -> [a]
+merge [] y = y
+merge x [] = x
+merge (x:xs) (y:ys) = if x <= y then x:(merge xs (y:ys)) else y:(merge (x:xs) ys)
+
+