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; } }
public void append(int value) { ListNode p = new ListNode(value); if (head == null) head = p; else tail.nextNode = p; tail = p; }
public void prepend(int val) { ListNode p = new ListNode(val); p.nextNode = head; head = p; }