please answer asap and correctly
One of the variations on a merge operation is to eliminate any duplicates whlie performing the merge. So the resulting merged array may be shorter than the sum of the lengths of the origina arrays. We will assume though, that the two input arrayLists of Objects each are unique, but sorted of course. The merge below uses ArrayLists (like Python lists) so we use the get() and addo methods for array access. public static ArrayList mergeUnique (ArrayList a, ArrayList b) int i = 0; int j - int cap; ArrayList m - new ArrayList(); while (i < a.size() && . 0 if (( .get(1).compareto a .get >)==0){ i++; //skip a duplicate } else if ( < 0) m.add .get(i++)); } else { m. add .get(++)); > //copy remaining elements over } while (i < 0) m.add(a. while (< O) m.add(a. return } The boxes are all options of a, b, m, i, j, c, get, add, size
One of the variations on a merge operation is to eliminate any duplicates whlie performing the merge. So the resulting m
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
One of the variations on a merge operation is to eliminate any duplicates whlie performing the merge. So the resulting m
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!