Skip to content

Instantly share code, notes, and snippets.

@5outh
Created Apr 3, 2012
Embed
What would you like to do?
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