Skip to content

Instantly share code, notes, and snippets.

@keyvanakbary
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save keyvanakbary/30e29aeee16bcafd8f92 to your computer and use it in GitHub Desktop.

Select an option

Save keyvanakbary/30e29aeee16bcafd8f92 to your computer and use it in GitHub Desktop.
(defn insertionsort [lns]
(let
[insert
(fn insert [n lns]
(if (or (empty? lns) (< n (first lns)))
(cons n lns)
(cons (first lns)
(insert n (rest lns)))))]
(loop [sns '()
lns lns]
(if (empty? lns)
sns
(recur
(insert (first lns) sns)
(rest lns))))))
(insertionsort '(3 4 12 3 45 1 -1 -30))
;;=> (-30 -1 1 3 3 4 12 45)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment