As much as I read about Queue interface I can only access the elements in the back and the front of the queue.
my question:
I want to check if "the same element" exist in the queue before I add a new one.
My first solution was to use for loop, run SIZE_OF_QUEUE iterations and every time to check if the element exist in the front of the queue and "raise a flag" if it does. In any case the element is poped and push to the back of the queue, and in any case the same number of iteration will be executed.
The disadvantage is that even if the element was found right away, the for loop will keep running.
I want to use a queue for this purpose, for I have to pop the oldest element first when I use them.
Is there another way to do it more efficiently?
thanks