【题目】
【分析】 建一个新链表 list = null
每次把链表的头摘下来,作为新链表的头。 head ->next = list ; list = head;
摘下来之前要保存一下下一个节点,防止下次找不到头了。所以: p = head.next; head ->next = list; list = head; head = p;
【代码】
【运行结果】
|
【题目】
【分析】 建一个新链表 list = null
每次把链表的头摘下来,作为新链表的头。 head ->next = list ; list = head;
摘下来之前要保存一下下一个节点,防止下次找不到头了。所以: p = head.next; head ->next = list; list = head; head = p;
【代码】
【运行结果】
|