1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "" "lang")((modname |26.3|) (read-case-sensitive #t) (teachpacks ((lib "" "teachpack" "htdp") (lib "" "teachpack" "htdp") (lib "" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "" "teachpack" "htdp") (lib "" "teachpack" "htdp") (lib "" "teachpack" "htdp")))))
4 ;qsort : (listof number) -> (listof number)
5 ;Uses generative recursion to quickly sort alon.
7 (define (qsort alon)
8 (cond
9 [(empty? alon) empty]
10 [else (append (qsort (filter (lambda (x) (< x (first alon)))
11 (rest alon)))
12 (list (first alon))
13 (qsort (filter (lambda (x) (> x (first alon)))
14 (rest alon))))]))
16 qsort-filter : (number number -> boolean) number (listof numbers) -> (listof numbers)
17 Returns a (listof numbers) for all numbers in alon that when compared to anumber satisfies (filter number alon).
19 (define (filter-qsort operator anumber alon)
21 (filter (lambda (x) (< x (first alon)))
22 (rest alon))