<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>

        反转链表?

        时间:2023-10-18

              <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.

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

                  上一篇:C++中的链表 下一篇:C++ 按排序顺序添加到链表

                  相关文章

                  <tfoot id='sX2iW'></tfoot>
                • <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>