<tfoot id='BaaST'></tfoot>

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

        为什么 std::list::reverse 具有 O(n) 复杂度?

        Why does std::list::reverse have O(n) complexity?(为什么 std::list::reverse 具有 O(n) 复杂度?)
          <legend id='lQLBM'><style id='lQLBM'><dir id='lQLBM'><q id='lQLBM'></q></dir></style></legend>

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

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

                  本文介绍了为什么 std::list::reverse 具有 O(n) 复杂度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为什么C++标准库中std::list类的reverse函数有线性运行时间?我认为对于双向链表,反向函数应该是 O(1).

                  Why does the reverse function for the std::list class in the C++ standard library have linear runtime? I would think that for doubly-linked lists the reverse function should have been O(1).

                  反转双向链表应该只涉及交换头指针和尾指针.

                  Reversing a doubly-linked list should just involve switching the head and the tail pointers.

                  推荐答案

                  假设,reverse 可能是 O(1).(再次假设)可能有一个布尔列表成员,指示当前链接列表的方向与创建列表的原始方向相同还是相反.

                  Hypothetically, reverse could have been O(1). There (again hypothetically) could have been a boolean list member indicating whether the direction of the linked list is currently the same or opposite as the original one where the list was created.

                  不幸的是,这会降低基本上任何其他操作的性能(尽管不会改变渐近运行时).在每个操作中,需要咨询一个布尔值来考虑是否跟随链接的下一个"或上一个"指针.

                  Unfortunately, that would reduce the performance of basically any other operation (albeit without changing the asymptotic runtime). In each operation, a boolean would need to be consulted to consider whether to follow a "next" or "prev" pointer of a link.

                  由于这可能被认为是相对不常见的操作,因此标准(不规定实现,只规定复杂性)规定复杂性可以是线性的.这允许下一个"指针始终明确表示相同的方向,从而加快常见情况的操作.

                  Since this was presumably considered a relatively infrequent operation, the standard (which does not dictate implementations, only complexity), specified that the complexity could be linear. This allows "next" pointers to always mean the same direction unambiguously, speeding up common-case operations.

                  这篇关于为什么 std::list::reverse 具有 O(n) 复杂度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is Type(::x); valid?(是类型(::x);有效的?)
                  Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                  Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                  Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                  No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                  Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)

                    <legend id='2Weve'><style id='2Weve'><dir id='2Weve'><q id='2Weve'></q></dir></style></legend>
                      <bdo id='2Weve'></bdo><ul id='2Weve'></ul>
                      <tfoot id='2Weve'></tfoot>

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

                        <small id='2Weve'></small><noframes id='2Weve'>

                          <tbody id='2Weve'></tbody>