Created
November 14, 2014 21:17
-
-
Save code-shoily/9c800d700920ddea868a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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