Created
May 9, 2010 15:08
-
-
Save gom/395217 to your computer and use it in GitHub Desktop.
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 characters
(use srfi-1) | |
(define (sort list) | |
(cond ((= (length list) 1) list) | |
(else (let* ((mid (/ (length list) 2)) | |
(left (sort (take list mid))) | |
(right (sort (drop list mid)))) | |
(merge left right))))) | |
(define (merge left right) | |
(cond ((or (null? left) (null? right)) | |
(append left right)) | |
((< (car left) (car right)) | |
(cons (car left) (merge (cdr left) right))) | |
(else | |
(cons (car right) (merge left (cdr right)))))) | |
(sort '(8 4 3 7 6 5 2 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment