How we Reverse the Queue ?
Basically, there are many method to reverse the array or queue.
Here, we reverse the queue with the use of the stack.
Process :
-Dequeue the Queue and push in stack until queue is empty
-then enqueue the queue by pop the stack until stack is empty
Following is the function which reverse the queue with the help of the queue :
void reverse()
{
while (!Queue.empty()) {
Stack.push(Queue.front());
Queue.dequeue();
}
while (!Stack.empty()) {
Queue.enqueue(Stack.top());
Stack.pop();
}
}