Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not that I know any Haskell, but wouldn't smallerSorted already include x due to <= operator?

edit: also, how is the pivot element selected there?



Both of your questions have the same answer. (x:xs) means x is the first element and xs is the rest.


Aha! Thanks.

Obviously picking first element as pivot makes for a very poor Quicksort. Though I presume a better approach, say median of first, mid and last elements, would add but an extra line?


The reason the first element is used as the pivot is that these are linked lists, not arrays, so it would take linear time to access the middle and end. This isn't a real quicksort.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: