You'll probably need to write two classes to create a linked list, one to act a a node (the class that has all elements you want in the node), and one to act as a manager of the list. The node class should, at least, have a member that holds a reference to the next node in the list. The manager class should, at least, have a member that holds a reference to the first node in the list.
When creating the list, you might do something like this.
java Code:
Node firstNode = new Node();
Node currentNode = firstNode;
//loop to create the desired number of nodes
{
Node n = new Node();
currentNode.setNextNode(n);
currentNode = n;
}
NodeManager nm= new NodeManager();
nm.setFirstNode(firstNode);
To find a node in the list, let the node manager have a method as such...
java Code:
public boolean find
(Object toFind
) { boolean ret = false;
Node currentNode = firstNode;
while(true) {
if (currentNode != null) {
if (currentNode == toFind) {
ret = true;
break;
}
else {
currentNode = currentNode.getNextNode();
}
else {
break;
}
}
return ret;
}
When creating new nodes, make sure to set the next node to null.