Skip to content

Instantly share code, notes, and snippets.

@code-shoily
Created November 14, 2014 21:17
Show Gist options
  • Save code-shoily/9c800d700920ddea868a to your computer and use it in GitHub Desktop.
Save code-shoily/9c800d700920ddea868a to your computer and use it in GitHub Desktop.
(defn quick-sort
"Takes a list and sorts it following the quick sort algorithm"
[lst]
(if (empty? lst) []
(concat
(quick-sort (filter (partial > (first lst)) (rest lst)))
(list (first lst))
(quick-sort (filter (partial <= (first lst)) (rest lst))))))
(defn quick-sort2
"Alternate, Haskell style quicksort- my personal favorite"
[lst]
(if (empty? lst) []
(let [[pivot & rst] lst]
(lazy-cat (quick-sort2 (for [before rst :when (< before pivot)] before))
[pivot]
(quick-sort2 (for [after rst :when (>= after pivot)] after))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment