Data Structures | Queue | Question 1
Following is C like pseudo-code of a function that takes a Queue as an argument, and uses a stack S to do processing.
What does the above function do in general?
Removes the last from Q
Keeps the Q same as it was before the call
Makes Q empty
Reverses the Q
The function takes a queue Q as an argument. It dequeues all items of Q and pushes them to a stack S. Then pops all items of S and enqueues the items back to Q. Since the stack is LIFO order, all items of the queue are reversed.
Hence option (D) is the correct answer.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!