Created
September 13, 2014 12:00
-
-
Save paomian/f7b3a512af2fc5badd38 to your computer and use it in GitHub Desktop.
clojure quick sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn nom [n] (take n (repeatedly #(rand-int n)))) | |
(defn sort-parts | |
[work] | |
(lazy-seq | |
(loop [[part & parts] work] | |
(if-let [[pivot & xs] (seq part)] | |
(let [smaller? #(< % pivot)] | |
(recur (list* | |
(filter smaller? xs) | |
pivot | |
(remove smaller? xs) | |
parts))) | |
(when-let [[x & parts] parts] | |
(cons x (sort-parts parts))))))) | |
(defn qsort [xs] | |
(sort-parts (list xs))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment