Why use two stacks to make a queue?

后端 未结 4 2320
醉话见心
醉话见心 2020-12-09 18:53

I can see the advantage of using two stacks if an array implementation is used since stacks are more easily implemented using arrays than queues are. But if linked-lists ar

4条回答
  •  孤城傲影
    2020-12-09 19:30

    You can make an immutable queue using two immutable stacks.

    But, if you just want a mutable queue, using two stacks is a great way to make it slower and more complicated than just using a linked list.

提交回复
热议问题