public ListNode setTail(ListNode newTail) { ListNode last = this; while (last.next != null) last = last.next; last.next = newTail; return this; }
public ListNode reverse() { ListNode prev = null; ListNode curr = this; while (curr != null) { ListNode tmp = curr.next; curr.next = prev; prev = curr; curr = tmp; } return prev; }