This problem need to use DrRacket software. Racket Language.
You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects.
Write a function (join-together L1 L2) that takes a sorted list (ascending) of integers L1 and a sorted list of elements L2 and returns a sorted list containing all elements of both L1 and L2. See the following examples for clarification.
(join-together '(3 12 18) '(-12 15 22)) ---> (-12 3 12 15 18 22) (join-together '() '(-12 15 22)) ---> (-12 15 18) (join-together '(3 12 18) '()) ---> (3 12 18) (join-together '(3 4 5) '(100 200 300 400 500 600)) ---> (3 4 5 100 200 300 400 500 600)
(define (join-together x y)
(cond
[(null? y) x]
[(null? x) y]
[(> (car y) (car x));
(cons (car x) (join-together (cdr x) y))]
;cons head x to (recurse)
[(cons (car y) (join-together x (cdr y)))]))
;cons head y to (recurse)
(print (join-together '(3 12 18) '(-12 15 22)))
(print (join-together '() '(-12 15 18)))
(print (join-together '(3 12 18) '()))
(print (join-together '(3 4 5) '(100 200 300 400 500 600)))
Get Answers For Free
Most questions answered within 1 hours.