我试图在列表的开头和结尾创建一个包含空对象的双向链表。空对象在列表的开头和结尾是什么意思。创建 firstNode =null 和 lastNode == null 会解决这个问题还是意味着不同的东西?任何建议将不胜感激。
// Creating a doubly linked list.
doubleLinkedList = new DoubleLinkedList();
class DoubleLinkedList {
private NewLink firstNode;
private NewLink lastNode;
private NewLink rootNode;
// Initializing values in the Constructor for DoubleLinkedList
public DoubleLinkedList() {
rootNode = null;
firstNode = null;
lastNode = null;
}
}
class NewLink {
public String data;
public NewLink nextPointer;
public NewLink previousPointer;
public NewLink(String id) {
data = id;
}
// Overriding toString method to return the actual data of the node
public String toString() {
return "{" + data + "} ";
}
}