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
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
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images