Page 1 of 1

One of the variations on a merge operation is to eliminate any duplicates whlie performing the merge. So the resulting m

Posted: Sun May 15, 2022 1:39 pm
by answerhappygod
One Of The Variations On A Merge Operation Is To Eliminate Any Duplicates Whlie Performing The Merge So The Resulting M 1
One Of The Variations On A Merge Operation Is To Eliminate Any Duplicates Whlie Performing The Merge So The Resulting M 1 (42.82 KiB) Viewed 89 times
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