
14.11 Linked Lists Using Generic Types 1085
49 head = head.getNext(); // delete head
50 else
51 previous.setNext( current.getNext());
52
53 numberOfItems--;
54 return true;
55 }
56 }
57 }
EXAMPLE 14.21 The GenericLinkedList Class with Generics
Our GenericLinkedList class, shown in Example 14.21, implements the
same methods as our PlayerLinkedList
The insert method, coded at lines 17–27, is very similar to the insert
method of the PlayerLinkedList class. Instead of a Player reference, its
parameter item is a T reference, where T is a generic class. It also inserts
item at the beginning of the list. At line 20, we declare and instantiate a
Node<T> object refer ...