Assume q passed into the function below is: q={10,9,8,7,6,5,4,3,2,1}
What would be the resulting queue (q) at the line below with the comment labeled //3.____
public Queue interChanger(Queue q){
Stack<Integer> st = new Stack<Integer>();
int size = q.size()/2;
for(int i = 1; i <= size; i++){
st.push(q.remove()); //1. ____________
}
while(!st.isEmpty()){
q.add(st.pop()); //2. ____________
}
for(int i = 1; i <= size; i++){
q.add(q.remove()); //3. ____________
}
for(int i = 1; i <= size; i++){
st.push(q.remove()); //4. ____________
}
while(!st.isEmpty()){
q.add(st.pop());
q.add(q.remove()); //5. ____________
}
return q;
}
|
67891054321 |
||
|
678910 |
||
|
12345678910 |
||
|
109876 |
Assume q passed into the function below is: q={10,9,8,7,6,5,4,3,2,1} What would be the resulting queue (q)...