Castle_Dust
Castle_Dust

Reputation: 63

What's the advantage of implementing queue with two stack?

I've heard that this way of implementation is cost-effective since Qing and deQing has amortized constant time complexity. Isn't that queueing with 2 pointers (head and tail) has also almost constant time complexity?

Upvotes: 1

Views: 156

Answers (1)

David Eisenstat
David Eisenstat

Reputation: 65458

Stacks have a trivial purely functional implementation; queues don't. This property and related ones (e.g., decorating the stacks to support a Minimum() operation so that the queue supports the same) cover all of the non-curiosity uses of which I'm aware.

Upvotes: 2

Related Questions