public void insertFirst(int newItem) { if (head == null) { head = new Node(newItem); } else { Node t = new Node(newItem); t.next = head; head = t; } }
public void insertLast(int newItem) { if (head == null) { head = new Node(newItem); } else { // traverse to the last and insert Node t = head; while (t.next != null) { t = t.next; } t.next = new Node(newItem); } }
public Node(int d) { this.data = d; next = null; arbitrary = null; }
public LL() { head = null; }