InterviewSolution
Saved Bookmarks
| 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.void fun(Queue *Q){Stack S; // Say it creates an empty stack S// Run while Q is not emptywhile (!isEmpty(Q)){// deQueue an item from Q and push the dequeued item to Spush(&S, deQueue(Q));}// Run while Stack S is not emptywhile (!isEmpty(&S)){// Pop an item from S and enqueue the poppped item to QenQueue(Q, pop(&S));}}What does the above function do in general?(A) Removes the last from Q(B) Keeps the Q same as it was before the call(C) Makes Q empty(D) Reverses the Q |
| Answer» | |