; Return the median of the numbers in values, a list of numbers. (define (median-by-sorting values) (list-ref (sort values) (half-length values)) ) ; Return the result of sorting the values in the list L. (define (sort L) (accumulate insert (cons (list (first L)) (rest L)) ) ) ; Return the list of numbers in the values list that are less than ; or equal to x. x is a number, values is a list of numbers. (define (smaller+equal-vals L x) (keep-if (lambda (y) (<= y x)) L) ) ; Return the list of numbers in the values list that are larger than x. ; x is a number, values is a list of numbers. (define (larger-vals L x) (keep-if (lambda (y) (> y x)) L) ) ; L is a sorted list. Return the result of inserting x into L ; in proper order. (define (insert L x) (append (smaller+equal-vals L x) (list x) (larger-vals L x) ) )