Write the following method that merges two sorted listsinto a new sorted list:public static int[] merge(int[] list1, int[] list2)Implement the method in a way that takes at most list1.length + list2.length comparisons. See liveexample.pearsoncmg.com/dsanimation/MergeSortNeweBook.html for an animation of the implementation. Write a testprogram that prompts the user to enter two sorted lists and displays the mergedlist. Here is a sample run. Note the first number in the input indicates the numberof the elements in the list. This number is not part of the list.     Enter list1 size and contents: 5 1 5 16 61 111↵EnterEnter list2 size and contents: 4 2 4 5 6↵Enterlist1 is 1 5 16 61 111list2 is 2 4 5 6The merged list is 1 2 4 5 5 6 16 61 111

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question

Write the following method that merges two sorted lists
into a new sorted list:
public static int[] merge(int[] list1, int[] list2)
Implement the method in a way that takes at most list1.length + list2.
length comparisons. See liveexample.pearsoncmg.com/dsanimation/MergeSortNeweBook.
html for an animation of the implementation. Write a test
program that prompts the user to enter two sorted lists and displays the merged
list. Here is a sample run. Note the first number in the input indicates the number
of the elements in the list. This number is not part of the list.

 

 

Enter list1 size and contents: 5 1 5 16 61 111↵Enter
Enter list2 size and contents: 4 2 4 5 6↵Enter
list1 is 1 5 16 61 111
list2 is 2 4 5 6
The merged list is 1 2 4 5 5 6 16 61 111

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Lists
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning