Created
January 5, 2016 01:20
-
-
Save gituser768/99bcd2c0ade1bf7f6630 to your computer and use it in GitHub Desktop.
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
(def my-list | |
[1 2 7 9 2 4 27 3 8 109 384 921 84 81722 94 92 7 4929 48 78 733 98 9 7 7 7 7 6 5 4332 9 2 1]) | |
(defn qsort | |
"Quicksort implementation" | |
[v] | |
(let [pivot (last v)] | |
(cond | |
(> (count v) 1) | |
(->> (vector ;; TODO Is there a better way to join three vectors? | |
(qsort (filter #(< % pivot) v)) | |
(filter #(= % pivot) v) | |
(qsort (filter #(> % (last v)) v))) | |
(flatten) | |
(apply vector)) | |
(= 1 (count v)) | |
pivot | |
:else | |
[]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment