这是《 Java中的数据结构和算法》(第六版)一书中的代码片段。该方法是LinkedPositionalList实现的一部分。我不确切了解这行的含义:“ if(node.getNext()== null)//已失效节点的约定”是针对的。我希望对其功能进行一些解释。
// private utilities
/** Validates the position and returns it as a node. */
private Node<E> validate(Position<E> p) throws IllegalArgumentException {
if (!(p instanceof Node)) throw new IllegalArgumentException("Invalid p");
Node<E> node = (Node<E>) p; // safe cast
if (node.getNext( ) == null) // convention for defunct node
throw new IllegalArgumentException("p is no longer in the list");
return node;
}
回首忆惘然
翻过高山走不出你
相关分类