Domanda di colloquio di Bloomberg

Implement a queue data structure using two stacks

Risposta di colloquio

Anonimo

20 set 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