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

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

        • <bdo id='tEP9D'></bdo><ul id='tEP9D'></ul>

        反转链表?

        reverse a linked list?(反转链表?)

              <bdo id='h1erR'></bdo><ul id='h1erR'></ul>
            • <tfoot id='h1erR'></tfoot>
            • <small id='h1erR'></small><noframes id='h1erR'>

                <tbody id='h1erR'></tbody>
                <legend id='h1erR'><style id='h1erR'><dir id='h1erR'><q id='h1erR'></q></dir></style></legend>

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

                  本文介绍了反转链表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试颠倒以下链接列表的顺序,我已经这样做了,但是颠倒的列表似乎没有打印出来.我哪里错了?

                  Im trying to reverse the order of the following linked list, I've done so, But the reversed list does not seem to print out. Where have I gone wrong?

                  //reverse the linked list
                      #include <iostream>
                      using namespace std;
                  
                      struct node{
                          int number;
                          node *next;
                      };
                  
                      node *A;
                  
                      void addNode(node *&listpointer, int num){
                          node *temp;
                          temp = new node;
                          temp->number = num;
                          temp->next = listpointer;
                          listpointer = temp;
                      }
                  
                      void reverseNode(node *&listpointer){
                          node *temp,*current;
                          current = listpointer;
                          temp = new node;
                          while (true){
                              if (current == NULL){
                                  temp = NULL;
                                  break;
                              }
                              temp->number = current->number;
                              current = current->next;
                              temp = temp->next;
                          }
                          listpointer = temp;
                      }
                  
                      int main(){
                          A = NULL;
                          addNode(A,1);
                          addNode(A,2);
                          addNode(A,3);
                  
                          while (true){
                              if (A == NULL){break;}
                              cout<< A->number << endl;
                              A = A->next;
                          }
                          cout<< "****" << endl;
                          reverseNode(A);
                  
                          while (true){
                              if (A == NULL){break;}
                              cout<< A->number << endl;
                              A = A->next;
                          }
                  
                          cout<< "****"<< endl;
                  
                          return 0;
                      }
                  

                  推荐答案

                  嗯,我注意到的第一件事就是你在做什么

                  Well, the first thing I notice is that you are doing

                  temp = 新节点

                  然后,在每次互动中:

                  temp = temp->next

                  temp = temp->next

                  但你永远不会分配 temp->next

                  but you are never assigning temp->next

                  因此,当您最终覆盖列表指针时,您肯定会返回一些有趣的值.

                  so when you finally override the list pointer you are surely giving back some funny value.

                  这篇关于反转链表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

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

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

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