<tfoot id='6uehI'></tfoot>

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

      1. 为什么链表使用指针而不是将节点存储在节点内

        Why do linked lists use pointers instead of storing nodes inside of nodes(为什么链表使用指针而不是将节点存储在节点内)

          • <tfoot id='s2Nex'></tfoot>

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

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

                  <bdo id='s2Nex'></bdo><ul id='s2Nex'></ul>
                • 本文介绍了为什么链表使用指针而不是将节点存储在节点内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我之前在 Java 中广泛使用过链表,但我对 C++ 非常陌生.我正在使用在项目中提供给我的这个节点类很好

                  I've worked with linked lists before extensively in Java, but I'm very new to C++. I was using this node class that was given to me in a project just fine

                  class Node
                  {
                    public:
                     Node(int data);
                  
                     int m_data;
                     Node *m_next;
                  };
                  

                  但是我有一个问题没有得到很好的回答.为什么要使用

                  but I had one question that wasn't answered very well. Why is it necessary to use

                  Node *m_next;
                  

                  指向列表中的下一个节点而不是

                  to point to the next node in the list instead of

                  Node m_next;
                  

                  我理解最好使用指针版本;我不会争论事实,但我不知道为什么这样更好.关于指针如何更好地进行内存分配,我得到了一个不太明确的答案,我想知道这里是否有人可以帮助我更好地理解这一点.

                  I understand that it is better to use the pointer version; I'm not going to argue facts, but I don't know why it's better. I got a not so clear answer about how the pointer is better for memory allocation, and I was wondering if anyone here could help me understand that better.

                  推荐答案

                  这不仅更好,而且是唯一可能的方法.

                  It's not just better, it's the only possible way.

                  如果你在自身内部存储了一个 Node object,那么 sizeof(Node) 会是什么?它将是 sizeof(int) + sizeof(Node),这将等于 sizeof(int) + (sizeof(int) + sizeof(Node)),即将等于 sizeof(int) + (sizeof(int) + (sizeof(int) + sizeof(Node))) 等到无穷大.

                  If you stored a Node object inside itself, what would sizeof(Node) be? It would be sizeof(int) + sizeof(Node), which would be equal to sizeof(int) + (sizeof(int) + sizeof(Node)), which would be equal to sizeof(int) + (sizeof(int) + (sizeof(int) + sizeof(Node))), etc. to infinity.

                  这样的对象是不可能存在的.这是不可能.

                  An object like that can't exist. It's impossible.

                  这篇关于为什么链表使用指针而不是将节点存储在节点内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 作为模板参数时出错)
                      • <bdo id='PtwCT'></bdo><ul id='PtwCT'></ul>
                          <tfoot id='PtwCT'></tfoot>
                              <tbody id='PtwCT'></tbody>

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

                          • <legend id='PtwCT'><style id='PtwCT'><dir id='PtwCT'><q id='PtwCT'></q></dir></style></legend>

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