25. Suppose we wish to merge two lists. Each list is already sorted and we want the merged list to also be sorted. Pleas
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
25. Suppose we wish to merge two lists. Each list is already sorted and we want the merged list to also be sorted. Pleas
25. Suppose we wish to merge two lists. Each list is already sorted and we want the merged list to also be sorted. Please implement the solution using recursion (i.e., calling yourself to process the rest of the list). You can assume that the parameters passed are actual lists (i.e., not just an atom) and does not contain sub-lists (i.e, it is a flat list). You are prohibited from merging the lists first then sorting the merged list. Some examples: > (my-merge '(4 5 6) '(1 2 3)) ?- my_merge([4, 5, 6], [1, 2, 3), Result). (1 2 3 4 5 6) Result = [1, 2, 3, 4, 5, 6]. > (my-merge '(1 3 5) '(2 4 6)) ?- my_merge([1, 3, 5), (2, 4, 6), Result). (1 2 3 4 5 6) [1, 2, 3, 4, 5, 6]. > (my-merge (1 2) (1 2 3 4 5)) ? - my_merge([1, 2), (1, 2, 3, 4, 5), Result). (1 1 2 2 3 4 5) Result [1, 1, 2, 2, 3, 4, 5]. Write your solutions on the page. Write a Prolog indicate my-morge.Clth List), Realt) that vetums a list as shown above Result = 8
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!