Permalink
Browse files

create function atHalf

  • Loading branch information...
1 parent 3a594ea commit 3da1ae53b3a1c12124d570bbf647fa296031aa1f @libscott committed Mar 18, 2012
Showing with 4 additions and 1 deletion.
  1. +4 −1 quick/quick.hs
View
@@ -1,5 +1,8 @@
import Data.List
+atHalf xs = xs !! (round $ realToFrac (length xs) / 2)
+
+
pivot :: Ord a => a -> [a] -> [a] -> [a] -> [a]
pivot n [] xs ys = quicksort xs ++ quicksort ys
pivot n (x:xs) ys zs = if (x < n)
@@ -10,4 +13,4 @@ pivot n (x:xs) ys zs = if (x < n)
quicksort :: Ord a => [a] -> [a]
quicksort [] = []
quicksort [x] = [x]
-quicksort xs = pivot (xs !! round (realToFrac (length xs) / 2)) xs [] []
+quicksort xs = pivot (atHalf xs) xs [] []

0 comments on commit 3da1ae5

Please sign in to comment.