/** * Die Liste pList wird an die Liste angehaengt. Anschliessend wird pList eine leere Liste. Das * aktuelle Objekt bleibt unveraendert. Falls pList null oder eine leere Liste ist, bleibt die * Liste unveraendert. * * @param pList Liste */ public void concat(List pList) { Node lCurrent1, lCurrent2, lPos0; if (pList != null && !pList.isEmpty()) { if (this.isEmpty()) { first = pList.first; tail = pList.tail; current = tail; } else { lPos0 = current; current = tail.getNext(); lCurrent1 = current; pList.toFirst(); current = pList.current; lCurrent2 = pList.current; lCurrent1.setNext(lCurrent2); if (lPos0 != tail) { current = lPos0; } else { current = pList.tail; } tail = pList.tail; } // pList wird zur leeren Liste pList.tail = new Node(null); // Dummy pList.first = pList.tail; pList.tail.setNext(tail); pList.current = pList.tail; } }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub ListFactory<String> factory = new ArrayListFactory<String>(); List<String> theList = factory.newInstance(); theList.add("Ron"); theList.add("Jil"); theList.add("Amy"); theList.add("Ron"); printList(theList); theList.add(0, "Apu"); theList.add(theList.size(), "Xi"); System.out.println("First element: " + theList.first()); System.out.println("Last element: " + theList.last()); printList(theList); theList.remove("Amy"); System.out.println("After removing Amy: " + theList.last()); printList(theList); theList.removeAll("Ron"); System.out.println("After removing all Ron: " + theList.last()); printList(theList); theList.add("Mel"); theList.add(1, "Cal"); printList(theList); theList.add("Cal"); printList(theList); System.out.println("First Index of Cal: " + theList.firstIndex("Cal")); System.out.println("Last Index of Cal: " + theList.lastIndex("Cal")); System.out.println("First Index of Xi: " + theList.firstIndex("Xi")); System.out.println("Last Index of Xi: " + theList.lastIndex("Xi")); System.out.println("First Index of Li: " + theList.firstIndex("Li")); System.out.println("Last Index of Li: " + theList.lastIndex("Li")); System.out.println("Element at position 2: " + theList.get(2)); theList.set(2, "Al"); System.out.println("Element at position 2: " + theList.get(2)); printList(theList); theList.clear(); printList(theList); }
protected Customer headOfQueue() { return (Customer) q.first(); }