Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Quickselect-algorithm/Haskell/quickselect-algorithm.hs
Normal file
18
Task/Quickselect-algorithm/Haskell/quickselect-algorithm.hs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import Data.List (partition)
|
||||
|
||||
quickselect
|
||||
:: Ord a
|
||||
=> [a] -> Int -> a
|
||||
quickselect (x:xs) k
|
||||
| k < l = quickselect ys k
|
||||
| k > l = quickselect zs (k - l - 1)
|
||||
| otherwise = x
|
||||
where
|
||||
(ys, zs) = partition (< x) xs
|
||||
l = length ys
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
print
|
||||
((fmap . quickselect) <*> zipWith const [0 ..] $
|
||||
[9, 8, 7, 6, 5, 0, 1, 2, 3, 4])
|
||||
Loading…
Add table
Add a link
Reference in a new issue