Skip to content

Instantly share code, notes, and snippets.

@devansh42
Last active December 30, 2020 10:01
Show Gist options
  • Save devansh42/db29875f104f7f8b278748e793e7c068 to your computer and use it in GitHub Desktop.
Save devansh42/db29875f104f7f8b278748e793e7c068 to your computer and use it in GitHub Desktop.
bubbleSort::(Ord a) => [a] -> [a]
bubbleSort [] = []
bubbleSort ([a]) = [a] -- One element array
bubbleSort ([a,b]) = if a<b then [a,b] else [b,a]
bubbleSort (a:b:bs) = let res = if a < b then [a] ++ bubbleSort([b]++bs) else [b] ++ bubbleSort([a]++bs) in bubbleSort (init res) ++ [last res]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment