单链表

单链表常见操作

1.如何实现一个单链表的逆序输出->反转单链表

public static ListNode reverse(ListNode head) {
ListNode prev = null;
ListNode next = null;
while (head != null && (next = head.next) != null) {
head.next = prev;
prev = head;
head = next;
}
head.next = prev;
return head;
}