21.4.3 Generic Classes ListNode and List
Generic class ListNode
(Fig. 21.3, lines 6–37) declares package-access fields data
and nextNode
. The data
field is a reference of type T
, so its type will be determined when the client code creates the corresponding List
object. Variable nextNode
stores a reference to the next ListNode
object in the linked list (or null
if the node is the last one in the list).
Lines 42–43 of class List
(Fig. 21.3, lines 40–47) declare references to the first and last ListNode
s in a List
(firstNode
and lastNode
, respectively). The constructors (lines 47–50 and 53–57) initialize both references to null
. The most important methods of class List
are insertAtFront
(lines 60–66), insertAtBack
(lines 69–75), removeFromFront ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.