Skip to content

Instantly share code, notes, and snippets.

@gituser768
Created January 5, 2016 01:20
Show Gist options
  • Save gituser768/99bcd2c0ade1bf7f6630 to your computer and use it in GitHub Desktop.
Save gituser768/99bcd2c0ade1bf7f6630 to your computer and use it in GitHub Desktop.
(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