tag:blogger.com,1999:blog-7056990295646173627.post6757343389580188281..comments2022-12-03T16:26:38.645+00:00Comments on Learning Clojure: Randomized QuicksortJohn Lawrence Aspdenhttp://www.blogger.com/profile/02587130870181071109noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-7056990295646173627.post-85270911255702090052013-08-07T03:17:11.829+01:002013-08-07T03:17:11.829+01:00That's really pretty! Thank you!That's really pretty! Thank you!John Lawrence Aspdenhttps://www.blogger.com/profile/02587130870181071109noreply@blogger.comtag:blogger.com,1999:blog-7056990295646173627.post-7261772179814864322013-07-12T00:51:17.162+01:002013-07-12T00:51:17.162+01:00Hi,
Just wanted to say thanks for the great Cloju...Hi,<br /><br />Just wanted to say thanks for the great Clojure blog and share with you my qsort. Sorry for the bad indentation...<br /><br />(defn qsort [s]<br /> (lazy-seq<br /> (when-let [[x & xs] s]<br /> (let [{:keys [lt gt]} (group-by #(if (< % x) :lt :gt) xs)]<br /> (concat (qsort lt) (cons x (qsort gt)))))))<br /><br />It performs well on random data and badly on sorted data as expected. I don't think this implementation would lend itself easily to the optimization you describe in this post, however, I'd like to point out in reality most of the time you know enough about the data you're sorting to know whether quicksort or some other sort is most appropriate.<br /><br />Thanks.Anonymousnoreply@blogger.com