Skip to content

Instantly share code, notes, and snippets.

@weefbellington
Created October 4, 2015 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weefbellington/b924220c93fde76fcb27 to your computer and use it in GitHub Desktop.
Save weefbellington/b924220c93fde76fcb27 to your computer and use it in GitHub Desktop.
Stupid haskell bubblesort
import Debug.Trace
main :: IO()
main = do
let sorted = bubbleSort [6, 5, 3, 1, 8, 7, 2, 4] :: [Integer]
print sorted
bubbleSort :: (Ord a, Show a) => [a] -> [a]
--bubbleSort lst | trace ("sorting: " ++ show lst) False = undefined
bubbleSort [] = []
bubbleSort [x] = [x]
bubbleSort (x:y:rest) =
bubbleSort (init bubbled) ++ [last bubbled]
where
(first, second) = if x > y then (y,x) else (x,y)
bubbled = first : bubbleSort (second:rest)
@mijail73
Copy link

how the fuck did U achieve that level hahahahhaha

@shankarnakai
Copy link

Ohh god, this is pretty good. Thanks by the example. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment