Last active
December 12, 2016 10:55
-
-
Save ayato-p/5905999 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 util.match) | |
(define (take p lst c) | |
(filter (lambda (x) (c p x)) | |
lst)) | |
(define (take-less p lst) | |
(take p lst >)) | |
(define (take-greater p lst) | |
(take p lst <)) | |
(define (quick-sort lst) | |
(match lst | |
[() '()] | |
[(first . rest) | |
(append (quick-sort (take-less first rest)) | |
(list first) | |
(quick-sort (take-greater first rest)))])) | |
(quick-sort '(3 9 2 8 4 1 0)) | |
(quick-sort '(0 0 0 0 0 1 2 2 2 2)) | |
(quick-sort '(0 0 0 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment