Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #reader(lib "htdp-intermediate-reader.ss" "lang")((modname 17.6.1) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "dir.ss" "teachpack" "htdp")))))
4 12687dd9 2023-08-04 jrmu ;A list-of-numbers (lon) is either
5 12687dd9 2023-08-04 jrmu ;1. empty or
6 12687dd9 2023-08-04 jrmu ;2. (cons n lon)
7 12687dd9 2023-08-04 jrmu ;where n is a number and lon is a list-of-numbers (lon).
8 12687dd9 2023-08-04 jrmu ;
9 12687dd9 2023-08-04 jrmu ;merge : lon lon -> lon
10 12687dd9 2023-08-04 jrmu ;Given lon1 and lon2, both lists-of-numbers arranged in ascending order, merge combines the two lists in ascending order and returns the list-of-numbers.
11 12687dd9 2023-08-04 jrmu
12 12687dd9 2023-08-04 jrmu (define (merge lon1 lon2)
13 12687dd9 2023-08-04 jrmu (cond
14 12687dd9 2023-08-04 jrmu [(and (empty? lon1)
15 12687dd9 2023-08-04 jrmu (empty? lon2)) empty]
16 12687dd9 2023-08-04 jrmu [(and (cons? lon1)
17 12687dd9 2023-08-04 jrmu (empty? lon2)) lon1]
18 12687dd9 2023-08-04 jrmu [(and (empty? lon1)
19 12687dd9 2023-08-04 jrmu (cons? lon2)) lon2]
20 12687dd9 2023-08-04 jrmu [(<= (first lon1) (first lon2)) (cons (first lon1)
21 12687dd9 2023-08-04 jrmu (merge (rest lon1) lon2))]
22 12687dd9 2023-08-04 jrmu [(> (first lon1) (first lon2)) (cons (first lon2)
23 12687dd9 2023-08-04 jrmu (merge lon1 (rest lon2)))]))
24 12687dd9 2023-08-04 jrmu
25 12687dd9 2023-08-04 jrmu (define list-1 '(1 3 5 7 9 21 23 25 27 29 31))
26 12687dd9 2023-08-04 jrmu (define list-2 '(2 4 6 8 10 12 14 16))