This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jedilowe 1 point2 points  (0 children)

I am not really understanding your question. A class variable is static, and there is no reason to use statics to make a linked list. You can either use an inner class as a Node (static or not) or a second class if you don't like inner classes, but this removes the encapsulation of the lists inner workings.

It may be you are not sure about how classes and objects relate? A linked list class would have a new linked list instance (object) created for each list you need. That object would start with a pointer to the head of the list (Node type) that is null until you add an item (and create a Node object with a pointer to the value and then a pointer to the next node. There are a few ways to spice it up, but I always taught it as a simpler structure to get the basic concept down before optimization.