Skip to content

Instantly share code, notes, and snippets.

@jboynyc
Created November 23, 2016 15:57
Show Gist options
  • Select an option

  • Save jboynyc/855e9cfdae6fbec6c23f352607cbb98d to your computer and use it in GitHub Desktop.

Select an option

Save jboynyc/855e9cfdae6fbec6c23f352607cbb98d to your computer and use it in GitHub Desktop.
quicksort in Chicken Scheme
(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