 Quote by rcgldr
I don't know Java, so I'm not sure if the next pointer should be placed first in a node class that has a variable data component.
|
That's not necessary, Java is quite good at handling memory itself.
 Quote by rcgldr
If you want the ability to determine if a node is in a list
|
then you should ask the list whether it contains a node. IMO you shouldn't even need to be able to create a node yourself (its constructor should be private).
 Quote by rcgldr
You could make this more generic by defining the node class to have a generic pointer to a data object (the equivalent of a void pointer in C), rather than including the actual data in the node class.
|
In Java, you would do this using generics, and declare a Node<T> object. Then you'd probably also have a List<T> with an add(T newElement) function that creates a Node<T>(newElement).