Skip to content

Instantly share code, notes, and snippets.

@5outh
Created April 3, 2012 06:06
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 5outh/2289676 to your computer and use it in GitHub Desktop.
Save 5outh/2289676 to your computer and use it in GitHub Desktop.
BubbleSort
bubbleSort :: (Ord a) => [a] -> [a]
bubbleSort [] = []
bubbleSort [x] = [x]
bubbleSort (x:y:xs) = if sorted thisSort then thisSort else bubbleSort thisSort
where thisSort = (min x y) : bubbleSort ((max x y):xs)
sorted :: (Ord a) => [a] -> Bool
sorted [] = True
sorted [x] = True
sorted (x:y:xs) = if x <= y then sorted (y:xs) else False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment