Skip to content

Instantly share code, notes, and snippets.

@kongscn
Created May 13, 2015 12:08
Show Gist options
  • Save kongscn/d47fa9cbe8055faf1114 to your computer and use it in GitHub Desktop.
Save kongscn/d47fa9cbe8055faf1114 to your computer and use it in GitHub Desktop.
QuickSort in Racket
#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