Skip to content

Instantly share code, notes, and snippets.

@mmagm
Created May 12, 2012 17:38
Show Gist options
  • Save mmagm/2667844 to your computer and use it in GitHub Desktop.
Save mmagm/2667844 to your computer and use it in GitHub Desktop.
bubble sort
import Data.List
bubble :: Ord a => [a] -> [a]
bubble [] = []
bubble [x] = [x]
bubble (x:x':xs) = case compare x x' of
GT -> x' : bubble (x:xs)
_ -> x : bubble (x':xs)
bubblesort :: Ord a => [a] -> [a]
bubblesort [] = []
bubblesort list = case bubble list of
bubbled | bubbled == list -> bubbled
| otherwise -> bubblesort bubbled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment