public void add(int x) { Node t = new Node(); t.data = x; Node tail = getTail(); if (tail == null) head = t; else tail.next = t; }
public static Node reverseList(Node head) { if (head == null) return head; Node pre = head; Node cur = head.next; Node next; while (cur != null) { next = cur.next; cur.next = pre; pre = cur; cur = next; } head.next = null; head = pre; return head; }