25. Suppose we wish to merge two lists. Each list is already sorted and we want the merged list to also be sorted. Pleas

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
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

Post by answerhappygod »

25 Suppose We Wish To Merge Two Lists Each List Is Already Sorted And We Want The Merged List To Also Be Sorted Pleas 1
25 Suppose We Wish To Merge Two Lists Each List Is Already Sorted And We Want The Merged List To Also Be Sorted Pleas 1 (30.95 KiB) Viewed 50 times
25 Suppose We Wish To Merge Two Lists Each List Is Already Sorted And We Want The Merged List To Also Be Sorted Pleas 2
25 Suppose We Wish To Merge Two Lists Each List Is Already Sorted And We Want The Merged List To Also Be Sorted Pleas 2 (30.95 KiB) Viewed 50 times
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 (ie, calling yourself to process the rest of the list). You can assume that the parameters passed are actual lists (.e., not just an atom) and does not contain sub-lists (ie, 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)) (1 2 3 4 5 6) > (my-merge *(1 3 5) (2 4 6)) (1 2 3 4 5 6) > (my-merge '(1 2) (1 2 3 4 5)) *(1 1 2 2 3 4 5) ?- my_merge([4, 5, 6), (1, 2, 3), Result). Result = (1, 2, 3, 4, 5, 6]. ?- my_merge([1, 3, 5), (2, 4, 6), Result). Result = [1, 2, 3, 4, 5, 6). ?- my_merge([1, 2], [1, 2, 3, 4, 5). Result). Result [1, 1, 2, 2, 3, 4, 5). Write a Rocket forebin (my-merge lit) let 2) thot murns a list as shown above Write your solutions on the next page. 8
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply