Write Public Static General Function Non Member Function Queue Class Alternately Merge Q1 Q37247272

Write a public static general function (non-member function ofqueue class) to alternately merge Q1’s items and Q2’s items to forma new merged Queue. For example, if Q1 is 100, 200, 300, 500, 600and Q2 is -100, -200, -300, after merging, the new merged queuewill be 100, -100, 200, -200, 300, -300, 500, 600.

Queue public static Queue MergeQueue(Queue Q1, Queue Q2);

Please do this in Java.


Answer


import java.util.LinkedList;
import java.util.Queue;
class Q{
public static Queue MergeQueue(Queue Q1,Queue Q2){
Queue<Integer>Q3 = new LinkedList<>();
int ct = 0; //If ct is even element Q1 elements will be addedotherwise Q2/
while(Q1.size() != 0 && Q2.size() != 0){
int rm;
if(ct % 2

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.