Advertisement
banovski

Bubble sort: terser and faster

Apr 21st, 2022 (edited)
1,422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sp :: [Integer] -> [Integer]
  2. sp (x:y:ys)
  3.   | x > y = y : sp (x : ys)
  4.   | otherwise = x : sp (y : ys)
  5. sp xs = xs
  6.  
  7. srt :: [Integer] -> [Integer]
  8. srt xs
  9.   | xs == sp xs = xs
  10.   | otherwise = srt $ sp xs
  11.  
  12. main :: IO [Integer]
  13. main = return $ srt [500,499 .. 0]
  14.  
  15. -- real    0m0,003s
  16. -- user    0m0,000s
  17. -- sys 0m0,003s
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement