I have a problem with queues in my program. Having one queue I would like to use this queue, only with another id. Here is what I have now:
queue<R> queue;
queue<R> queue2;
...
while (! queue2.empty() )
{
R r = queue2.front();
queue2.pop();
queue.push(r);
}
But it is linear. I hope that it is possible to do it in O(1) time. I tried to use references but I failed.
You didn’t tell us how you “failed”, but references are really easy:
Job done.