Array-Based vs List-Based Stacks and Queues

后端 未结 2 1114
囚心锁ツ
囚心锁ツ 2020-12-12 09:39

I\'m trying to compare the growth rates (both run-time and space) for stack and queue operations when implemented as both arrays and as linked lists. So far I\'ve only been

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-12 10:02

    Sorry if I misunderstood your question, but if I didn't, than I believe this is the answer you are looking for.

    With a vector, you can only efficiently add/delete elements at the end of the container. With a deque, you can efficiently add/delete elements at the beginning/end of the container. With a list, you can efficiently insert/delete elements anywhere in the container.

    vectors/deque allow for random access iterators. lists only allow sequential access.

    How you need to use and store the data is how you determine which is most appropriate.

    EDIT:

    There is a lot more to this, my answer is very generalized. I can go into more depth if I'm even on track of what your question is about.

提交回复
热议问题