且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

双重链接列表Deque实现

更新时间:2021-08-10 01:13:12

我看不到你增加大小变量的任何地方。

你在 isEmpty中依赖它方法,但它没有在 insertFirst 方法中递增。



希望这有帮助,

Fredrik
I can't see any place where you're increasing the size variable.
You're relying on it in the isEmpty method but it's not incremented in the insertFirst method.

Hope this helps,
Fredrik


removeLast必须如下:



removeLast must be like:

if (!isEmpty()) {
  Node<T> last = trailer.getPrev();
  T o = last.getElement();
  Node<T> secondtolast = last.getPrev();
  trailer.setPrev(secondtolast);
  secondtolast.setNext(trailer);
  size--;
  return o;
  } else {
    throw new DequeEmptyException("Deque is empty!");
  }