Frage im Vorstellungsgespräch bei Amazon

implement a queue from stack

Antworten zu Vorstellungsgespräch

Anonym

18. Feb. 2012

Agreed - an implementation class Queue { private: stack q; stack s; public: push(int x) { s.push(); }; int pop() { if(q.empty()) { while(x = s.pop()) q.push(); }; return q.pop(); }; };

2

Anonym

16. Feb. 2012

using two stacks. one as head of the queue, the other as the tail of the queue