示例#1
0
 public void delete(int val) {
   ListNode p = head, prev = null;
   while (p != null && p.value != val) {
     prev = p;
     p = p.nextNode;
   }
   if (p != null) {
     if (p == head) head = p.nextNode;
     else prev.nextNode = p.nextNode;
     if (tail == p) tail = prev;
   }
 }
示例#2
0
 public void append(int value) {
   ListNode p = new ListNode(value);
   if (head == null) head = p;
   else tail.nextNode = p;
   tail = p;
 }
示例#3
0
 public void prepend(int val) {
   ListNode p = new ListNode(val);
   p.nextNode = head;
   head = p;
 }