quicksort

quicksort - (define (smaller-than anum alon) (cond [(empty?...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#| function is named quick-sort since quicksort is built in. Note: need to be in intermediate language level to use local |# ; quick-sort : list-of-number ->list-of-number ; sorts list into increasing order (define (quick-sort alon) (cond [(empty? alon) empty] [(cons? alon) (local [(define pivot (first alon))] (append (quick-sort (smaller-than pivot (rest alon))) (list pivot) (quick-sort (larger-than pivot (rest alon)))))])) ; smaller-than : number list-of-number -> list-of-number ; produces list of nums from original list that are smaller than given number
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: (define (smaller-than anum alon) (cond [(empty? alon) empty] [(cons? alon) (cond [(< (first alon) anum) (cons (first alon) (smaller-than anum (rest alon)))] [else (smaller-than anum (rest alon))])])) ; larger-than : number list-of-number -> list-of-number ; produces list of nums from original list that are larger than given number (define (larger-than anum alon) (cond [(empty? alon) empty] [(cons? alon) (cond [(> (first alon) anum) (cons (first alon) (larger-than anum (rest alon)))] [else (larger-than anum (rest alon))])]))...
View Full Document

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

Ask a homework question - tutors are online