标签:
单链表的反转,每次循环需要四步骤。
public ListNode reverse(ListNode head) { if(head == null || head.next == null) { return head; } ListNode pPre = head; ListNode pCurr = head.next; ListNode pNext = null; head.next = null; while(pCurr != null) { pNext = pCurr.next; pCurr.next = pPre; pPre = pCurr; pCurr = pNext; } return pPre; }
标签:
原文地址:http://www.cnblogs.com/masterlibin/p/5630131.html