This is not a HW or assignment. This is something i\'m practicing myself.
Given a queue, write a Reverse method reverses elements of a queue. MyQueue remains unchan
I've used two different approaches that don't depend on your queue size. The first one uses Stack and second one - Java 8 Stream API (the fastest).
The most effective solution for reversing queue in my tests is:
private Queue reverse(Queue queue) {
List collect = queue.stream()
.collect(Collectors.toList());
Collections.reverse(collect);
return new LinkedList<>(collect);
}