Skip to content

Instantly share code, notes, and snippets.

@lambrospetrou
Created November 5, 2017 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambrospetrou/970bcf188eb6061e1bfbfa9e36c29042 to your computer and use it in GitHub Desktop.
Save lambrospetrou/970bcf188eb6061e1bfbfa9e36c29042 to your computer and use it in GitHub Desktop.
Quick-sort implementation in Racket
#lang racket
(define (qsrt iarr lt)
(cond
[(< 1 (length iarr))
(let (
[pivot (first iarr)]
[gt (lambda (l r) (not (or (lt l r) (equal? l r))))])
(append
(qsrt (filter (lambda (x) (lt x pivot)) iarr) lt)
(filter (lambda (x) (equal? x pivot)) iarr)
(qsrt (filter (lambda (x) (gt x pivot)) iarr) lt)))]
[else iarr]))
(qsrt '("hello" "world" "hi" "hell") string<?)
(qsrt '(6 5 4 7 4 2 1 8 9 0) <)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment