Assignment #10: Functions as ArgumentsOut: Wednesday, March 18th Due: Thursday, March 26th, 4:00pm |
This homework must be done and submitted with your partner. Please see the submissions page for details on how to submit with your partner.
Note: You cannot write the structure definition
provided by the text book, because the function pair?
was added to the student languages after the text was published.
Use a different name for the structure, such as:
(define-struct pair2 (left right)) |
sort function,
which we developed in class:
;; sort : Listof[Number] -> Listof[Number]
;; to construct a list with all items from alon in descending order
(define (sort alon)
(local ((define (insert an alon)
(cond
[(empty? alon) (list an)]
[else (cond
[(> an (first alon)) (cons an alon)]
[else (cons (first alon) (insert an (rest alon)))])])))
(cond
[(empty? alon) empty]
[else (insert (first alon) (sort (rest alon)))]))) |
sort function which
consumes the comparison as an additional argument. sort-ascending and sort-descending,
which sort a Listof[Number] in ascending and descending
order, respectively.
find:
;; find : Symbol Listof[Symbol] -> Boolean
;; determine if the symbol is in the list
(define (find s l)
(cond [(empty? l) false]
[else (or (symbol=? s (first l))
(find s (rest l)))])) |
find function to take an input which is a
Question[Symbol] instead of a Symbol
find to handle lists of any kind of data.
Does this require any changes to the body of find?