package sort;
public class Test24 {
public static void main(String[] args) {
ListNode head = new ListNode(0, null);
ListNode temp = head;
for (int i = 1; i < 100; i++) {
temp.next = new ListNode(i, null);
temp = temp.next;
}
ListNode result = revese(head);
while (result != null) {
System.out.println(result.date);
result = result.next;
}
}
private static ListNode revese(ListNode head) {
ListNode root = new ListNode(0);//使用临时节点方便操作
ListNode next = null;
while (head != null) {
next = head.next;//用来保存原链表的下一个节点
head.next = root.next;//将当前链表的第一个节点使用头插法插入到链表中
root.next = head;
head = next; //head节点向后移动一位
}
return root.next;
}
}
1168

被折叠的 条评论
为什么被折叠?



