;; sort: list-of-number -> list-of-number ;; sorts a list of numbers into ascending order (define (sort alon) (cond [(empty? alon) empty ] [(cons? alon) (insert (first alon) (sort (rest alon))) ])) ;; test (check-expect (sort (list 3 4 2 1)) (list 1 2 3 4)) ;; insert: number list-of-number(sorted) -> list-of-number (sorted) ;; consumes a number and a sorted list of numbers and produces a new sorted list with ;; the number inserted in the correct place (define (insert num aslon) (cond [(empty? aslon) (list num)] [(cons? aslon) (cond [(< num (first aslon)) (cons num aslon)] [else (cons (first aslon) (insert num (rest aslon)) )]) ])) ;; test (check-expect (insert 3 empty) (list 3)) (check-expect (insert 3 (list 1 2 4)) (list 1 2 3 4)) ;; people-with-kids: person -> list of string ;; consumes a person and produces a list of the names of all people in the tree who have children (define (people-with-kids adt) (cond [(cons? (person-children adt)) (cons (person-name adt) (kids-with-kids (person-children adt)))] [else empty])) ;; kids-with-kids: list-of-person -> list-of-string ;; consume a list of person and produce a list of the names of everyone who has children (define (kids-with-kids alop) (cond [(empty? alop) empty] [(cons? alop) (append (people-with-kids (first alop)) (kids-with-kids (rest alop)))])) (check-expect (people-with-kids SusanTree) (list "Susan" "Helen"))