Skip to content

Instantly share code, notes, and snippets.

@ayato-p
Last active December 12, 2016 10:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayato-p/5905999 to your computer and use it in GitHub Desktop.
Save ayato-p/5905999 to your computer and use it in GitHub Desktop.
(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