Skip to content

Instantly share code, notes, and snippets.

@msysyamamoto
Created October 21, 2012 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msysyamamoto/3925883 to your computer and use it in GitHub Desktop.
Save msysyamamoto/3925883 to your computer and use it in GitHub Desktop.
bubble sort
import Data.List
import Test.QuickCheck
bubbleSort :: Ord a => [a] -> [a]
bubbleSort [] = []
bubbleSort [x] = [x]
bubbleSort xs = bubbleSort zs ++ z
where
(zs, z) = splitAt (length xs - 1) $ bubble xs
bubble (y0:y1:ys)
| y0 <= y1 = y0 : bubble (y1:ys)
| otherwise = y1 : bubble (y0:ys)
bubble ys = ys
prop_bubbleSort :: [Int] -> Bool
prop_bubbleSort xs = bubbleSort xs == sort xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment