Question: Write a method public static ArrayList mergeSorted(ArrayList a, ArrayList b) that merges two sorted array lists, producing a new sorted array list. Keep an index
Write a method
public static ArrayList mergeSorted(ArrayList a,
ArrayList b)
that merges two sorted array lists, producing a new sorted array list. Keep an index into each array list, indicating how much of it has been processed already. Each time, append the smallest unprocessed element from either array list, then advance the index. For example, if a is 1 4 9 16 and b is 4 7 9 9 11 then mergeSorted returns the array list 1 4 4 7 9 9 9 11 16
Step by Step Solution
3.32 Rating (152 Votes )
There are 3 Steps involved in it
Program screenshots Sample output Code to copy import the necessary package import javautilAr... View full answer
Get step-by-step solutions from verified subject matter experts
