嗨,我对Java很陌生,并且在构建双向链接列表的嵌套迭代器类时遇到此问题。我不确定如何编写一个public E next()
方法,让它遍历双链表。双重链接列表上的Java迭代器
任何帮助,非常感谢!
private class DoubleListIterator implements Iterator<E> {
// instance variable
private Node current=head;
private Node last;
private int index=0;
public boolean hasNext() {
return index < N;
}
public E next() {
if (!hasNext()) throw new NoSuchElementException();
}
public void remove() { throw new UnsupportedOperationException(); }
}// end class ListIterator
顺便说一下,在我的解决方案中,字段名'current'不正确。如果您接受我的解决方案,请将其重命名为“next”或“cursor”。 –