Frage im Vorstellungsgespräch bei Clearwater Analytics (CWAN)

Write an implementation of a queue using only a stack class. The queue class should support the Enqueue() and Dequeue() methods.

Antworten zu Vorstellungsgespräch

Anonym

29. Sept. 2011

This is obviously a questions from a computer science course and not something useful that an engineer would ever want to do.

1

Anonym

17. Okt. 2012

Use two stacks, S1 and S2. When enqueuing, pop everything from S1 and push, in order, to S2. Then push the element. Then pop everything from S2 back to S1. When dequeuing, just pop for the first element.