Created
November 23, 2016 15:57
-
-
Save jboynyc/855e9cfdae6fbec6c23f352607cbb98d to your computer and use it in GitHub Desktop.
quicksort in Chicken Scheme
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) ; provides filter | |
| (define (quicksort elems) | |
| (if (null? elems) (list) | |
| (let [[middle (car elems)] | |
| [others (cdr elems)]] | |
| (let [[left (filter (lambda (x) (<= x middle)) others)] | |
| [right (filter (lambda (x) (> x middle)) others)]] | |
| (append (quicksort left) (cons middle (quicksort right))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment