Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer the following questions in scheme programming language 1.merge* takes two lists of numbers that may contain sublists. The numbers in each part of

Please answer the following questions in scheme programming language

1.merge* takes two lists of numbers that may contain sublists. The numbers in each part of the lists are in non-decreasing sorted order, but the numbers inside a sublist do not have to be in order with numbers outside the sublist, and numbers after the sublist do not have to be larger than those before. So '(4 5 6 (1 2 (1 4 5) 1 6 7) 1 2 3) is a valid ordering because each "piece" from one open/close parenthesis to the next is in sorted order. merge* will merge in order all the numbers from each list up to any sublist, recurse on the sublists, and then merge any values after the sublists. If there are more sublists, this process repeats. If one list ends when the other has more sublists, then all contents of the second list are added to the end of the output list.

> (merge* '(4 5 6 (1 2 (1 4 5) 1 (6 7)) 1 2 3) '(1 3 7 8 (4 6 (3 4 8) (6 8 9) 10) 0 4 (10))) '(1 3 4 5 6 7 8 (1 2 4 6 (1 3 4 4 5 8) 1 (6 6 7 8 9) 10) 0 1 2 3 4 (10))

2.samestructure takes two lists that may contain sublists. The function should return #t if the two lists have the same structure of sublists even if the atoms and number of atoms of each sublist is different. (This is equivalent to asking whether two lists are the same if we first empty both lists of atoms. However, write this list using a single pass through the data.)

> (samestructure '((a) b c ((d) e)) '(a b (c) d e (f g (h (i))) k)) #f > (samestructure '((a) b c ((d) e)) '(a b (c) d e (f g (h i)) k)) #t

3.deepnest takes a list of atoms and returns a list with the same atoms but each consecutive atom in a sublist that is nested inside the current list.

> (deepnest '(a b c d e)) '(a (b (c (d (e)))))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions