Created
May 12, 2012 17:38
-
-
Save mmagm/2667844 to your computer and use it in GitHub Desktop.
bubble sort
This file contains 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
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