反转链表

Posted zhwcs

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了反转链表相关的知识,希望对你有一定的参考价值。

    public ListNode ReverseList(ListNode head) {
      if(head==null||head.next==null) return head;
      ListNode pReverseHead=null;
      ListNode pNode=head;
      ListNode pPrev=null;
      while(pNode!=null){
          ListNode pNext=pNode.next;
          if(pNode!=null) pReverseHead=pNode;
          pNode.next=pPrev;
          pPrev=pNode;
          pNode=pNext;
      }
      return pReverseHead;
    }

 

以上是关于反转链表的主要内容,如果未能解决你的问题,请参考以下文章