Created
July 14, 2013 21:23
-
-
Save j1n3l0/5996158 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
(ns adaa) | |
(defn merger | |
[a b c] | |
(if (every? empty? [a b]) | |
c | |
(cond | |
(empty? a) (merger a (rest b) (conj c (first b))) | |
(empty? b) (merger (rest a) b (conj c (first a))) | |
:else (if (< (first a) (first b)) | |
(merger (rest a) b (conj c (first a))) | |
(merger a (rest b) (conj c (first b))))))) | |
(defn merge-sort | |
[coll] | |
(let [n (count coll) m (/ n 2)] | |
(if (<= n 1) | |
coll | |
(merger (merge-sort (take m coll)) (merge-sort (drop m coll)) [])))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My first pass at merge sort. Causes a stack overflow at around n = 4000 ... so not very good :( Looking at this gist now for inspiration.