Last active
August 29, 2015 14:11
-
-
Save firstspring1845/753c266a8c7a12e879e2 to your computer and use it in GitHub Desktop.
マージソートに驚いた人「マージで?」
This file contains 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 characters
(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