haskell: naive quicksort classic program (+5 tests, 395/395)

This commit is contained in:
2026-04-25 18:06:41 +00:00
parent d33c520318
commit a12dcef327
2 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
-- quicksort.hs — naive functional quicksort.
--
-- Partition by pivot, recurse on each half, concatenate.
-- Uses right sections `(< x)` and `(>= x)` with filter.
qsort [] = []
qsort (x:xs) = qsort smaller ++ [x] ++ qsort larger
where
smaller = filter (< x) xs
larger = filter (>= x) xs
result = qsort [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]