2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,14 +1,13 @@
|
|||
(defn merge* [left right]
|
||||
(defn merge [left right]
|
||||
(cond (nil? left) right
|
||||
(nil? right) left
|
||||
true (let [[l & *left] left
|
||||
[r & *right] right]
|
||||
(if (<= l r) (cons l (merge* *left right))
|
||||
(cons r (merge* left *right))))))
|
||||
:else (let [[l & *left] left
|
||||
[r & *right] right]
|
||||
(if (<= l r) (cons l (merge *left right))
|
||||
(cons r (merge left *right))))))
|
||||
|
||||
(defn merge-sort [L]
|
||||
(let [[l & *L] L]
|
||||
(if (nil? *L)
|
||||
L
|
||||
(let [[left right] (split-at (/ (count L) 2) L)]
|
||||
(merge* (merge-sort left) (merge-sort right))))))
|
||||
(defn merge-sort [list]
|
||||
(if (< (count list) 2)
|
||||
list
|
||||
(let [[left right] (split-at (/ (count list) 2) list)]
|
||||
(merge (merge-sort left) (merge-sort right)))))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue