fork download
  1. import Data.List (iterate)
  2.  
  3. bubbleStep [x] = [x]
  4. bubbleStep (x:y:ys) | x > y = y : bubbleStep (x:ys) | otherwise = x : bubbleStep (y:ys)
  5. bubbleSort xs = iterate bubbleStep xs !! length xs
  6.  
  7. main = print (bubbleSort [64, 34, 25, 12, 22, 11, 90, 5, 45, 1])
  8.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
[1,5,11,12,22,25,34,45,64,90]