When working with a doubly linked list, it is important to keep in mind the previous pointer. Lets look at the node class:

private static class Node {
public Node() { } // the constructor
int item;
Node next;
Node prev;

This is our nested class that is the ‘blueprint’ to our Node object. If we want to create the node object, we must use the word new: “Node newNode = new Node()”. In java, this actually creates a Node object and is not just a pointer. On the other hand: “Node point”, is how we create just a pointer. The two pieces of code do different things and you should know when to use them. The first should be used when actually adding a new Node to a linked list. The other can be used to help refer to nodes when manipulating a list. Note, a pointer can point to any node all you have to do is use the ‘=’ sign. For example, if I type “point = newNode”, then pointer (“point“) is pointing towards newNode. We can access the information in newNode (i.e., prev, next, and item) in 2 ways: ‘’ or ‘’.

Leave a Reply

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