Created
April 3, 2012 06:07
-
-
Save 5outh/2289680 to your computer and use it in GitHub Desktop.
BubbleSort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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