deque和list STL容器之间有什么区别? [英] What's the difference between deque and list STL containers?

查看:102
本文介绍了deque和list STL容器之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两者之间有什么区别?我的意思是方法都一样.因此,对于用户而言,它们的工作原理相同.

What is the difference between the two? I mean the methods are all the same. So, for a user, they work identically.

正确吗?

推荐答案

摘自(但很有用的) deque 的SGI STL :

From the (dated but still very useful) SGI STL summary of deque:

双端队列非常像一个向量:就像一个向量,它是一个序列,它支持对元素的随机访问,序列末尾的恒定时间插入和删除元素以及线性时间中元素的线性插入和删除.中间.

A deque is very much like a vector: like vector, it is a sequence that supports random access to elements, constant time insertion and removal of elements at the end of the sequence, and linear time insertion and removal of elements in the middle.

双端队列与向量不同的主要方式是,双端队列还支持在序列开始时恒定时间插入和删除元素.另外,deque没有类似于vector的Capacity()和reserve()的任何成员函数,并且不提供与那些成员函数相关的迭代器有效性的任何保证.

The main way in which deque differs from vector is that deque also supports constant time insertion and removal of elements at the beginning of the sequence. Additionally, deque does not have any member functions analogous to vector's capacity() and reserve(), and does not provide any of the guarantees on iterator validity that are associated with those member functions.

以下是同一站点上 list 上的摘要:

Here's the summary on list from the same site:

列表是双向链接列表.也就是说,它是一个序列,它支持向前和向后遍历,以及在开始或结束时或在中间(恒定)固定时间插入和删除元素.列表具有重要的属性,即插入和拼接不会使迭代器失效,甚至删除也只会使指向被删除元素的迭代器无效.迭代器的顺序可以更改(即list :: iterator在执行列表操作后可能具有与之前不同的前任或后继者),但是除非该无效,否则迭代器本身不会失效或指向不同的元素.或突变是明显的.

A list is a doubly linked list. That is, it is a Sequence that supports both forward and backward traversal, and (amortized) constant time insertion and removal of elements at the beginning or the end, or in the middle. Lists have the important property that insertion and splicing do not invalidate iterators to list elements, and that even removal invalidates only the iterators that point to the elements that are removed. The ordering of iterators may be changed (that is, list::iterator might have a different predecessor or successor after a list operation than it did before), but the iterators themselves will not be invalidated or made to point to different elements unless that invalidation or mutation is explicit.

总而言之,容器可能具有共享的例程,但是这些例程的时间保证因容器而异.在考虑使用哪个容器执行任务时,这一点非常重要:考虑如何容器将被最频繁地使用(例如,用于搜索而不是用于插入/删除)会很长的路要走将您定向到正确的容器.

In summary the containers may have shared routines but the time guarantees for those routines differ from container to container. This is very important when considering which of these containers to use for a task: taking into account how the container will be most frequently used (e.g., more for searching than for insertion/deletion) goes a long way in directing you to the right container.

这篇关于deque和list STL容器之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆