Question: /* * mergeQueues * * precondition: input queues q1, q2 may be empty * postconditions: * return a new queue containing merged contents of q1,q2

/*

* mergeQueues

*

* precondition: input queues q1, q2 may be empty

* postconditions:

* return a new queue containing merged contents of q1,q2 using

* an every-other-one policy - starting with q1

* if queues are not the same length, the 'tail' of the longer one ends

* up getting appended to the result - see examples below

*

* original queues are empty

*

* you may use: basic java arrays, Stack<>, Queue<> from algs13

* you may NOT use any other Java classes, algorithms without permission

*

* your solution must be all client code: you may not alter the original Stack, Queue classes

*

* In the examples below, the left-most values are at the front of the queues

* Examples:

* q1: abcd , q2: wxyz mergeQueues(q1,q2) --> awbxcydz

* q1: abc , q2: xy mergeQueues(q1,q2) --> axbyc

* q1: ab , q2: xyz mergeQueues(q1,q2) --> axbyz

* q1: abc , q2: mergeQueues(q1,q2) --> abc

* q1: , q2: mergeQueues(q1,q2) -->

* merge

*/

public static Queue mergeQueues(Queue q1,Queue q2) {

return new Queue(); // To Do 2 fix this

}

/*

* equalQueues

*

* two queues are equal if they are the same size and all corresponding items are the same

* precondition: input queues q1, q2 may be empty

* postconditions:

* return true if the two queues are identical and false otherwise

* original queues are unchanged

*

* you may use: basic java arrays, Stack<>, Queue<> from algs13

* you may not use any other Java classes, algorithms without permission

*

* your solution must be all client code: you may not alter the original Stack, Queue classes

*

* you MAY NOT use the toString method of the Stack or Queue classes

*

* In the examples below, the left-most values are at the front of the queues

* Examples:

* q1: abcd , q2: abcd equalQueues(q1,q2) --> true

* q1: abc , q2: xy equalQueues(q1,q2) --> false

* q1: a , q2: xyz equalQueues(q1,q2) --> false

* q1: a , q2: equalQueues(q1,q2) --> false

* q1: a , q2: a equalQueues(q1,q2) --> true

*

*/

public static boolean equalQueues( Queue q1, Queue q2) {

return false; // To Do 3 fix this

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!