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

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

      1. <tfoot id='wYt3T'></tfoot>
      2. STL 中的双端队列到底是什么?

        时间:2024-05-12
        • <legend id='BYtzL'><style id='BYtzL'><dir id='BYtzL'><q id='BYtzL'></q></dir></style></legend>

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

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

              <tfoot id='BYtzL'></tfoot>
                    <tbody id='BYtzL'></tbody>
                  本文介绍了STL 中的双端队列到底是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在查看 STL 容器并试图弄清楚它们到底是什么(即使用的数据结构),deque 阻止了我:我一开始以为它是一个双链表,这将允许在恒定时间内从两端插入和删除,但我对

                  在 vector 的比较进行了很好的分析Depth-Study-of-the-STL-Deque-Container" rel="noreferrer">CodeProject.

                  GCC 标准库实现内部使用一个 T** 来表示地图.每个数据块都是一个T*,它被分配了一些固定大小的__deque_buf_size(取决于sizeof(T)).

                  I was looking at STL containers and trying to figure what they really are (i.e. the data structure used), and the deque stopped me: I thought at first that it was a double linked list, which would allow insertion and deletion from both ends in constant time, but I am troubled by the promise made by the operator [] to be done in constant time. In a linked list, arbitrary access should be O(n), right?

                  And if it's a dynamic array, how can it add elements in constant time? It should be mentioned that reallocation may happen, and that O(1) is an amortized cost, like for a vector.

                  So I wonder what is this structure that allows arbitrary access in constant time, and at the same time never needs to be moved to a new bigger place.

                  解决方案

                  A deque is somewhat recursively defined: internally it maintains a double-ended queue of chunks of fixed size. Each chunk is a vector, and the queue ("map" in the graphic below) of chunks itself is also a vector.

                  There’s a great analysis of the performance characteristics and how it compares to the vector over at CodeProject.

                  The GCC standard library implementation internally uses a T** to represent the map. Each data block is a T* which is allocated with some fixed size __deque_buf_size (which depends on sizeof(T)).

                  这篇关于STL 中的双端队列到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么使用 std::auto_ptr&lt;&gt; 是错误的?使用标准容器? 下一篇:为什么标准迭代器范围是 [begin, end) 而不是 [begin, end]?

                  相关文章

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

                      <legend id='xuqz5'><style id='xuqz5'><dir id='xuqz5'><q id='xuqz5'></q></dir></style></legend>

                    1. <small id='xuqz5'></small><noframes id='xuqz5'>