• <i id='tCmjg'><tr id='tCmjg'><dt id='tCmjg'><q id='tCmjg'><span id='tCmjg'><b id='tCmjg'><form id='tCmjg'><ins id='tCmjg'></ins><ul id='tCmjg'></ul><sub id='tCmjg'></sub></form><legend id='tCmjg'></legend><bdo id='tCmjg'><pre id='tCmjg'><center id='tCmjg'></center></pre></bdo></b><th id='tCmjg'></th></span></q></dt></tr></i><div id='tCmjg'><tfoot id='tCmjg'></tfoot><dl id='tCmjg'><fieldset id='tCmjg'></fieldset></dl></div>
    <tfoot id='tCmjg'></tfoot>

    <small id='tCmjg'></small><noframes id='tCmjg'>

      • <bdo id='tCmjg'></bdo><ul id='tCmjg'></ul>
        <legend id='tCmjg'><style id='tCmjg'><dir id='tCmjg'><q id='tCmjg'></q></dir></style></legend>

        deque 和 list STL 容器有什么区别?

        时间:2024-08-13
      1. <i id='icU8i'><tr id='icU8i'><dt id='icU8i'><q id='icU8i'><span id='icU8i'><b id='icU8i'><form id='icU8i'><ins id='icU8i'></ins><ul id='icU8i'></ul><sub id='icU8i'></sub></form><legend id='icU8i'></legend><bdo id='icU8i'><pre id='icU8i'><center id='icU8i'></center></pre></bdo></b><th id='icU8i'></th></span></q></dt></tr></i><div id='icU8i'><tfoot id='icU8i'></tfoot><dl id='icU8i'><fieldset id='icU8i'></fieldset></dl></div>

          <small id='icU8i'></small><noframes id='icU8i'>

          • <bdo id='icU8i'></bdo><ul id='icU8i'></ul>
              <tbody id='icU8i'></tbody>

                <tfoot id='icU8i'></tfoot>

                • <legend id='icU8i'><style id='icU8i'><dir id='icU8i'><q id='icU8i'></q></dir></style></legend>
                • 本文介绍了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.

                  正确吗??

                  推荐答案

                  来自(过时但仍然非常有用)SGI STL 总结 deque:

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

                  一个deque很像一个vector:和vector一样,它是一个序列,支持元素的随机访问,序列末尾元素的恒定时间插入和移除,以及序列中元素的线性时间插入和移除中.

                  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 不同的主要方式是 deque 还支持常量时间插入和移除序列开头的元素.此外,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:

                  列表是双向链表.也就是说,它是一个 Sequence,既支持前向遍历,也支持后向遍历,以及(分摊的)常量时间在开头或结尾或中间插入和移除元素.列表有一个重要的特性,即插入和拼接不会使列表元素的迭代器失效,即使删除也只会使指向被删除元素的迭代器失效.迭代器的顺序可能会改变(也就是说,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 容器有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:什么是容器/适配器?C++ 下一篇:如何从 std::vector<string> 构造 std::string?

                  相关文章

                  <tfoot id='xabfo'></tfoot>

                      <bdo id='xabfo'></bdo><ul id='xabfo'></ul>
                  1. <legend id='xabfo'><style id='xabfo'><dir id='xabfo'><q id='xabfo'></q></dir></style></legend>
                  2. <small id='xabfo'></small><noframes id='xabfo'>

                  3. <i id='xabfo'><tr id='xabfo'><dt id='xabfo'><q id='xabfo'><span id='xabfo'><b id='xabfo'><form id='xabfo'><ins id='xabfo'></ins><ul id='xabfo'></ul><sub id='xabfo'></sub></form><legend id='xabfo'></legend><bdo id='xabfo'><pre id='xabfo'><center id='xabfo'></center></pre></bdo></b><th id='xabfo'></th></span></q></dt></tr></i><div id='xabfo'><tfoot id='xabfo'></tfoot><dl id='xabfo'><fieldset id='xabfo'></fieldset></dl></div>