I have 2 set of unsorted integers: set A and set B. But we don't know how many items are there in setB in advance.
I need to :
while setA and setB are not empty:
pop the smallest no from setA
move an int from setB to setA
What is the most efficient way to do that in Java?
I am thinking
- create an ArrayList for setA and LinkedList for setB
- while (setA and setB are not empty) sort(setA) pop setA remove an integer from setB and insert in setA
Is there a better way to do this in Java? I would like to remove the 'sort in the while loop' if possible.