Question d’entretien chez Bloomberg

Implement a queue data structure using two stacks

Réponse à la question d'entretien

Utilisateur anonyme

20 sept. 2010

Queue - First In Last Out Insert the elements into the stack one by one. For removing, use another stack. Pop all the elements from the original stack and insert in the second stack. Now if we pop the element from the second stack, that will be in FIFO order. Basically -(-1) = 1, so Stack(stack) = Queue