Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #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 ;A list-of-numbers (lon) is either
5 ;1. empty or
6 ;2. (cons n lon)
7 ;where n is a number and lon is a list-of-numbers (lon).
8 ;
9 ;merge : lon lon -> lon
10 ;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.
12 (define (merge lon1 lon2)
13 (cond
14 [(and (empty? lon1)
15 (empty? lon2)) empty]
16 [(and (cons? lon1)
17 (empty? lon2)) lon1]
18 [(and (empty? lon1)
19 (cons? lon2)) lon2]
20 [(<= (first lon1) (first lon2)) (cons (first lon1)
21 (merge (rest lon1) lon2))]
22 [(> (first lon1) (first lon2)) (cons (first lon2)
23 (merge lon1 (rest lon2)))]))
25 (define list-1 '(1 3 5 7 9 21 23 25 27 29 31))
26 (define list-2 '(2 4 6 8 10 12 14 16))