quicksort (deriving filter)

How to Design Programs: An Introduction to Programming and Computing

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

View Full Document Right Arrow Icon
;; 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))])])) ;; ----------------------------------------------------------------------
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
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 Right Arrow Icon
Ask a homework question - tutors are online