public class Node {
Object data;
Node next;
Node(Object o) {
data = o;
next = null;
}
Node getNext() {
return next;
}
public void setNext(Node n) {
n.next = next;
next = n;
}
}
The main thing to notice is that instead of having a pointer to the next Node, you just use the next node itself. Of course itıs really just a pointer so nothing is lost and some clarity is gained.