// generates a list of the elements in the collection // Postcondion: list is independant (deep copy) of original collection public List<T> createList() { List<T> list = new ArrayList<T>(); LLNode<T> temp = node; while (temp.getLink() != null) { list.add(temp.getInfo()); temp = temp.getLink(); } list.add(temp.getInfo()); return list; }
// Returns the element if this collection contains an element e such that // e.compareTo(element) == 0; otherwise, returns null. public T fetch(T element) { if (size == 0) { return null; } else { LLNode<T> temp = node; while (temp.getLink() != null) { if (element.compareTo(temp.getInfo()) == 0) { return temp.getInfo(); } temp = temp.getLink(); } if (temp.getInfo().compareTo(element) == 0) { return temp.getInfo(); } } return null; }