Skip to content

Instantly share code, notes, and snippets.

@firstspring1845
Last active August 29, 2015 14:11
Show Gist options
  • Save firstspring1845/753c266a8c7a12e879e2 to your computer and use it in GitHub Desktop.
Save firstspring1845/753c266a8c7a12e879e2 to your computer and use it in GitHub Desktop.
マージソートに驚いた人「マージで?」
(defun msort (list pred)
(cond ((not (consp (car list)))
(msort (mapcar (lambda (x) (cons x NIL)) list) pred))
((equal (cdr list) NIL)
(car list))
(t
(let (merged)
(loop
(push (merge 'list (pop list) (pop list) pred) merged)
(if (not list) (return (msort merged pred))))))))
(princ (msort '(1 9 2 8 3 7 4 6 5) #'<))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment