[racket] missing solution 19.1.6 ex:abs-sort
A candidate for a solution.
;; sort1 : list-of-numbers -> list-of-numbers
;; to construct a list with all items from alon in descending order
(define (sort1 cmp alon)
(local ((define (sort alon)
(cond
[(empty? alon) empty]
[else (insert (first alon) (sort (rest alon)))]))
(define (insert an alon)
(cond
[(empty? alon) (list an)]
[else (cond
[(cmp an (first alon)) (cons an alon)]
[else (cons (first alon) (insert an (rest
alon)))])])))
(sort alon)))
(check-expect (sort1 < (list 2 3 1 5 4)) (list 1 2 3 4 5))
(check-expect (sort1 > (list 2 3 1 5 4)) (list 5 4 3 2 1))
Source:
http://www.htdp.org/2003-09-26/Solutions/abs-sort.html
No Solution Written, yet Unfortunately, the solution to this exercise has
not yet been written. To submit a solution you have written to this
problem, or to complain that the solution isn't available, please contact Robby
Findler
<robby at eecs.northwestern.edu?subject=missing%20solution%2019.1.6%20ex:abs-sort%20>
.
To see the list of solutions, visit the table of contents
<http://www.htdp.org/2003-09-26/Solutions/contents.html>. Each of the
hyperlinked exercise numbers has a solution.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20140829/a8528959/attachment.html>