/** Adds to the end of the list */ public void add(Object o) { MergableLinkedList.Node n = new Node(o); if (head == null) { // first node head = n; } else { tail.next = n; } tail = n; size++; }
/** * This is the reason this class exists. This is an optimized way to add all the elements in List * m to the front of this List. At the end of this call the List m is cleared. */ public void mergeToFront(MergableLinkedList m) { if (m.isEmpty()) { // Nothing to merge return; } m.tail.next = head; head = m.head; if (tail == null) { tail = m.tail; } size += m.size(); m.clear(); }