Practice Generic Nodes

In this assignment you are to implement a generic Node class with a type parameter for the
elements stored in a linked list.
Exercises – Requirements
1. (2 pts) Add a generic Node class to your Java project.
2. (16 pts total) In the class
(2 pts) Declare the usual fields data and link; follow the book specification but use
the generic type parameter as necessary
(8 pts) Define the accessor methods and mutator methods for both fields)
(6 pts) Define an initializer constructor, see the book
Remember the generic syntax: at the definition the name of the constructor is
Node, however every time you use Node for a type you must postfix the generic;
when the constructor is used to instantiate a Node object a concrete type for the
generic parameter like Node<String> must be used
3. (56 pts total, 8 pts each) Define the Node class methods as required below.
Define the addNodeAfter( ) method as explained in the PP presentation, use the
generic type as needed.
Define removeNodeAfter( ) method as explained in the PP presentation, use the
generic type as needed.
Define a non-static listLength( ) method; no parameter; the method iterates thru
the list from the calling object (this), counts the nodes and returns the count; use
while loop for iteration
Define a static listLength( ) method, see the book; must use its own generic type;
takes a node parameter; the method iterates thru the list from parameter node),
counts the nodes and returns the count; use for loop for iteration
Define a static listSearch ( ) method, see the book; must use its own generic type;
takes a node parameter, and a data parameter, both generic; the method iterates
thru the list from parameter node, checks if data is target (use the equals( )

Leave a Reply

Your email address will not be published. Required fields are marked *