From haskell.org:
quicksort :: Ord a => [a] -> [a]
quicksort [] = []
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
where
lesser = filter (< p) xs
greater = filter (>= p) xs
My question is which word does “p” stand for here? In other words, why (p:xs)
rather than (x:xs)
?
I just spotted the answer:
(p:xs)
pattern on its left-hand side standing for non-empty list with the head elementp
(used as a pivot element)
“p” stands for “pivot”.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With