All pastes #1471359 Raw Edit

Anonymous

public text v1 · immutable
#1471359 ·published 2009-06-23 16:46 UTC
rendered paste body
mergesort :: (Ord a) => [a] -> [a]
mergesort [] = []
mergesort (x:xs) = let halfLength xs = truncate $ (fromIntegral . length) xs / 2
	  	       (left, right) = splitAt (halfLength (x:xs)) (x:xs)
		       merge :: (Ord a) => [a] -> [a] -> [a]
		       merge [] _ = []
		       merge _ [] = []
		       merge (x:xs) (y:ys)
		       	     | x > y = x : xs `merge` (y:ys)
		       	     | x <= y = y : (x:xs) `merge` ys
			     | otherwise = x : y : xs `merge` ys
		   in mergesort left `merge` mergesort right