I need to create a second ArrayQueue of the same type that is passed in, so I can items in the Queue. I cannot instantiate the second ArrayQueue unless I make it of a specific class which defeats the purpose of the generic and fails the tests when the test switches from Integer, Character, Object, or Boolean.
The test cases pass in an ArrayQueue to operate on, but the code needs to create a second ArrayQueue of the same type that is passed in. I tried using as the type but it does not compile.
Example
If … entering the adjacentPairs method the queue were front [ 12, 34, 56, 78, 90 ] back
Then … exiting the adjacentPairs method the queue would be front [ 34, 12, 78, 56, 90 ] back
public class Swap
{
public static void adjacentPairs (ArrayQueue arr) throws NullPointerException
{
if(arr.isEmpty())
{
return;
}
int n = arr.size();//finding size
for(int i=0;i<n;i=i+2)
{
if(i+1<n)
{//swapping adjacentpairs
ArrayQueue a = new ArrayQueue(????, n);//to swap
a.enqueue(arr.dequeue());
arr.enqueue(arr.dequeue());
arr.enqueue(a.dequeue());
}
else
arr.enqueue(arr.dequeue());
}
}
}