Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
(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
Owner

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
Something went wrong with that request. Please try again.