Skip to content

Instantly share code, notes, and snippets.

@j1n3l0
Created July 14, 2013 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j1n3l0/5996158 to your computer and use it in GitHub Desktop.
Save j1n3l0/5996158 to your computer and use it in GitHub Desktop.
(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)) []))))
@j1n3l0
Copy link
Author

j1n3l0 commented Jul 14, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment