I am using
Queue<T> q1 and I know that an element will be added using
q1.offer(); at the end of the queue. But now, what I want to do is add an element in front of queue, which is not possible with Queue. The possible methods I could think of are
- Use of double ended queue and I can add the elements in front and at the end.
- reverse the q1, add the element at the end of the queue and reverse again.
Now, as a non-programmer guy, I am not sure, how to code these methods; which one is more economical and easier to do.
Problems I faced in 1) is transform of existing Queue to Deque and vice versa; and in 2) How to use
Collections.reverseOrder(); to reverse the existing Queue.