Java – reverse method reverses the elements of the queue

This is not a hardware or task This is something I practice myself

Given a queue, write a reverse method to reverse the elements of the queue Myqueue remains unchanged

Signature:

public Queue<T> reverse(Queue<T> myQueue) {

Note: it is not known whether the queue is created using nodes or arrays

The queue has implemented the methods we can use:

void enqueue(T element)
T dequeue();
boolean isFull();
boolean isEmpty();
int size();

Solution

>Dequeue the elements of the input queue to the stack > pop elements from the stack and queue each element to the output queue

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>