q1, ArrayQueue q2){Iterator iter1 = q1.iterator();while (iter1.hasNext()){int a = iter1.next();int b = q2.poll();if (a > b)q2.offer(a);elseq2.offer(b):}}Corresponding elements of q1 and...


What is the purpose of the following method? Assume that both q1 and q2 are not empty and contains the same number of<br>elements.<br>public class QueueEx<br>{<br>public static void method1(ArrayQueue<Integer> q1, ArrayQueue<Integer> q2)<br>{<br>Iterator<Integer> iter1 = q1.iterator();<br>while (iter1.hasNext())<br>{<br>int a = iter1.next();<br>int b = q2.poll();<br>if (a > b)<br>q2.offer(a);<br>else<br>q2.offer(b):<br>}<br>}<br>Corresponding elements of q1 and q2 are compared, q1 will contain the greater and q2 will contain the smaller among<br>the corresponding elements of q1 and q2.<br>Corresponding elements of q1 and q2 are compared. q1 will contain the smaller and q2 will contain the greater among<br>B<br>the corresponding elements of q1 and q2.<br>Corresponding elements of q1 and q2 are compared. q1 will remain unchanged and q2 will contain the elements which<br>are greater among the corresponding elements of q1 and q2.<br>D<br>All elements of q1 which are greater than the first element of q1 will be added to q2.<br>

Extracted text: What is the purpose of the following method? Assume that both q1 and q2 are not empty and contains the same number of elements. public class QueueEx { public static void method1(ArrayQueue q1, ArrayQueue q2) { Iterator iter1 = q1.iterator(); while (iter1.hasNext()) { int a = iter1.next(); int b = q2.poll(); if (a > b) q2.offer(a); else q2.offer(b): } } Corresponding elements of q1 and q2 are compared, q1 will contain the greater and q2 will contain the smaller among the corresponding elements of q1 and q2. Corresponding elements of q1 and q2 are compared. q1 will contain the smaller and q2 will contain the greater among B the corresponding elements of q1 and q2. Corresponding elements of q1 and q2 are compared. q1 will remain unchanged and q2 will contain the elements which are greater among the corresponding elements of q1 and q2. D All elements of q1 which are greater than the first element of q1 will be added to q2.
Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here