Initially queue contains elements like 6,8,9,2
I)while statement is true.
II)dequeue from queue and push into stack until queue becomes enpty.
stack values are from top to bottom in order 2,9,8,6.//after completion of first while loop
III)2nd while loop pop one value from stack and enqueue into queue until stack becomes empty.
initially pop top value from stack i.e)2 and enqueue into queue.
after 2nd while loop false contents of queue is 2,9,8,6.
Hence it reverses the elements in queue