Last active
August 29, 2015 13:58
Revisions
-
kohyama revised this gist
Apr 9, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ (nil? bh) a (< ah bh) (cons ah (m [ar b])) :else (cons bh (m [a br])))) (map merge-sort (split-at (quot c 2) ks)))))) (defn quick-sort [[k & ks]] (if (nil? k) [] -
kohyama created this gist
Apr 9, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ (defn insertion-sort [ks] (reduce (fn [a x] (let [[h t] (split-with #(< % x) a)] (concat h [x] t))) [] ks)) (defn merge-sort [ks] (let [c (count ks)] (if (= c 1) ks ((fn m [[[ah & ar :as a] [bh & br :as b]]] (cond (nil? ah) b (nil? bh) a (< ah bh) (cons ah (m [ar b])) :else (cons bh (m [a br])))) (map merge-sort (split-at (quot c 2) ks)))))) (defn quick-sort [[k & ks]] (if (nil? k) [] (apply #(concat %1 [k] %2) (map quick-sort (reduce (fn [[a b] x] (if (< k x) [a (conj b x)] [(conj a x) b])) [[] []] ks)))))