; insert : alpha list-of-alpha (alpha alpha -> boolean) -> list-of-alpha ; assumes the input list is sorted by in-order? ; returns a new sorted (by in-order?) list with the input value in it (define (insert x in-order? a-lox) (cond [(empty? a-lox) (cons x empty)] [(cons? a-lox) (cond [(in-order? x (first a-lox)) (cons x a-lox)] [else (cons (first a-lox) (insert x (rest a-lox) in-order?))])])) ; isort : list-of-alpha -> list-of-alpha ; returns a new sorted (by in-order?) version of the input list (define (isort a-lox in-order?) (foldr (lambda (f r) (insert f in-order? r)) empty a-lox)) ; sort a list of numbers in non-descending order (isort (list 2 98 43 1) <) ; sort a list of lists in non-ascending order of lengths (isort (list (list 1 2 3 4) (list 'a 'b 'd 'e 'y) (list 3 1) (list 56 2 2435)) (lambda (l1 l2) (> (length l1) (length l2))))