Created
May 13, 2015 12:08
-
-
Save kongscn/d47fa9cbe8055faf1114 to your computer and use it in GitHub Desktop.
QuickSort 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 (qsort a) | |
(cond | |
[(empty? a) a] | |
[else (let* | |
([hd (first a)] | |
[tl (rest a)] | |
[smaller (filter (lambda (x) (< x hd)) tl)] | |
[bigger (filter (lambda (x) (>= x hd)) tl)]) | |
(append (qsort smaller) (list hd) (qsort bigger)))])) | |
(require math/distributions) | |
(define ary (sample (normal-dist 0 1) 1000000)) | |
(time (let ([x (qsort ary)]) 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment