-
|
On the last line of the first Hutton pwp, we get the following snippet of code: mystery [] = []
mystery (x:xs) = mystery ys ++ [x] ++ mystery zs
where
ys = [a | a <- xs, a <= x]
zs = [a | a <- xs, a > x]Here's my understanding of the code, please correct me if I'm wrong:
So if I remember correctly from ADS (which would be a miracle), this is Quicksort? |
Beta Was this translation helpful? Give feedback.
Answered by
wence-
Jan 14, 2021
Replies: 1 comment 2 replies
-
|
A miracle has occurred! This is indeed quicksort. The non-empty list is partitioned around a pivot element (we just pick the head of the list) into elements <= the pivot or > the pivot. Then, we recurse to sort those bits. |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
wence-
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A miracle has occurred! This is indeed quicksort.
The non-empty list is partitioned around a pivot element (we just pick the head of the list) into elements <= the pivot or > the pivot. Then, we recurse to sort those bits.