示例#1
0
  public void add(int x) {
    Node t = new Node();
    t.data = x;

    Node tail = getTail();
    if (tail == null) head = t;
    else tail.next = t;
  }
示例#2
0
 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;
 }