quicksort (deriving filter)

# How to Design Programs: An Introduction to Programming and Computing

This preview shows pages 1–2. Sign up to view the full content.

;; qsort : list-of-number -> list-of-number[sorted] ;; sorts a list of numbers into increasing order (define (qsort alon) (cond [(empty? alon) empty] [(cons? alon) (append (qsort (smaller-than (first alon) (rest alon))) (list (first alon)) (qsort (larger-than (first alon) (rest alon))))])) ;; smaller-than : number list-of-number -> list-of-number ;; extracts all numbers from list that are smaller than given number (define (smaller-than num alon) (cond [(empty? alon) empty] [(cons? alon) (cond [(< (first alon) num) (cons (first alon) (smaller-than num (rest alon)))] [else (smaller-than num (rest alon))])])) ;; larger-than : number list-of-number -> list-of-number ;; extracts all numbers from list that are larger than given number (define (larger-than num alon) (cond [(empty? alon) empty] [(cons? alon) (cond [(> (first alon) num) (cons (first alon) (larger-than num (rest alon)))] [else (larger-than num (rest alon))])])) ;; ----------------------------------------------------------------------

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/06/2008 for the course CS 536 taught by Professor Fisler during the Fall '07 term at WPI.

### Page1 / 2

quicksort (deriving filter) - ; qsort : list-of-number ->

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online