参考一下,理解目的就比较好理解了。容易混乱的地方就是从右往左来处理,因为得先把后面的东西存起来,不然被覆盖掉就丢了。
pre head
+----+ +----+ +> +----+
| | | | | | |
| | | | | | |
| | | | | | |
+----+ +----+ | +----+
| | | | | | |
| | | | | | |
+----+ +-+--+ | +----+
| |
+-----+
pre head next next = head.next;
+----+ +----+ +> +----+
| | | | | | |
| | | | | | |
| | | | | | |
+----+ +----+ | +----+
| | | | | | |
| | | | | | |
+----+ +-+--+ | +----+
| |
+-----+
pre head next
+----+
| | | | | | |
| | | | | | |
| | | | | | |
+----+ | +----+ +----+
| | | | | | |
| | | | | | |
+----+ | +-+--+ +----+
| | head.next = pre;
+----+
next
pre head pre = head;
+----+
| | | | | | |
| | | | | | |
| | | | | | |
+----+ | +----+ +----+
| | | | | | |
| | | | | | |
+----+ | +-+--+ +----+
| |
+----+