I have my own ArrayQueue Class which has methods for enqueue, dequeue and peek etc. My ArrayQmerge class extends this Class and contains:
public void mergeQs(ArrayQmerge q){
}
I was wondering whats the best way to write a method to merge an ArrayQueue with another Queue without removing any elements from the q thats passed.
eg. queue1 = [1,2,3,4,11] and queue2 = [5,6,7,8,9,10,12].
When queue1.mergeQs(queue2) is called it will create queue1 = [1,5,2,6,3,7,4,8,11,9,10,12] whilst queue2 would remain [5,6,7,8,9,10,12]
I want the mergeQs method to interleave the elements from the two queues if that makes sense. I know how to successfully add them together or using a method which passes both Queues as arguments but in this case i want to use the above method(which only passes one)…
This is what you can do:
Here is output: