zoukankan      html  css  js  c++  java
  • 剑指offer15-反转链表

    输入一个链表,反转链表后,输出新链表的表头。

    思路:pre指向第一个节点,current指向下个节点,while current不是空,保存current的下个节点,令current->next=pre;pre=current;current=current->next;

        ListNode* ReverseList(ListNode* pHead) {
            ListNode *pre,*nextNode,*current;
            if(pHead==NULL||pHead->next==NULL) return pHead;
            pre=pHead;
            current=pHead->next;
            pHead->next=NULL;
            while(current!=NULL)
            {
                nextNode=current->next;
                current->next=pre;
                pre=current;
                current=nextNode;
            }
            //current->next=pre;
            //Rhead=current;
            return pre;
        }

  • 相关阅读:
    第一次项目总结
    8.16 CSS知识点7
    2016y9m22d 博文分享
    2016y9m8d
    2016y9m7d
    2016y9m6d
    2016y9m5d
    2016.9.2博文分享!
    2016y8m16d
    2016y8m15d
  • 原文地址:https://www.cnblogs.com/trouble-easy/p/12962156.html
Copyright © 2011-2022 走看看