Skip to content

Instantly share code, notes, and snippets.

@Ikke
Created August 9, 2014 15:27
Show Gist options
  • Save Ikke/2fa9f39ca1459ebf87ec to your computer and use it in GitHub Desktop.
Save Ikke/2fa9f39ca1459ebf87ec to your computer and use it in GitHub Desktop.
bubblesort :: (Ord a) => [a] -> [a]
bubblesort [] = []
bubblesort (x1:x2:xs) =
let sorted = if x2 < x1
then x2 : bubblesort (x1:xs)
else x1 : bubblesort (x2:xs)
in (bubblesort $ init sorted) ++ [last sorted]
bubblesort xs = xs
main = do
let foo = bubblesort [5,2,4,8,1,3,7]
print foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment