;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-intermediate-lambda-reader.ss" "lang")((modname merge_sort) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))))) ;; Exercise 26.1.2. ;; contract: list of numbers -> list of lists of numbers ;; the function takes a list and produces a list of lists ;; in which every list contains exactly one element of the ;; given list (define (make-singles lon) (cond [(empty? lon) empty] [else (cons (list (first lon)) (make-singles (rest lon)) ) ] ) ) (check-expect (make-singles (list 2 5 9 3)) (list (list 2) (list 5) (list 9) (list 3))) (define (merge lon1 lon2) (cond [(empty? lon1) lon2] [(empty? lon2) lon1] [(< (first lon1) (first lon2)) (cons (first lon1) (merge (rest lon1) lon2))] [else (cons (first lon2) (merge lon1 (rest lon2)))]) ) (check-expect (merge (list 1 4 5) (list 2 3 6)) (list 1 2 3 4 5 6)) ;; contract: list of lists -> list of lists ;; Write the purpose. Any assumptions that we need to make? ;(define (merge-all-neighbors lol) ;) ;(check-expect (merge-all-neighbors (list (list 2) (list 5) (list 9) (list 3))) ; (list (list 2 5) (list 3 9))) ;(check-expect (merge-all-neighbors (list (list 2 5) (list 3 9))) ; (list (list 2 3 5 9))) ;(check-expect (merge-all-neighbors (list (list 2 5) (list 3 9) (list 7 8))) ; (list (list 2 3 5 9) (list 7 8))) ;(check-expect ; (merge-sort (list 1 6 3 5 7 4 2)) ; (list 1 2 3 4 5 6 7))