Created
November 5, 2017 01:48
-
-
Save lambrospetrou/970bcf188eb6061e1bfbfa9e36c29042 to your computer and use it in GitHub Desktop.
Quick-sort implementation in Racket
This file contains 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
#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