-6

快速的问题。如果我像这样从 LinkedList 中删除元素

playerDeck.remove(0);

或者像这样

playerDeck.removeFirst(); 

列表的第一个元素会是空白吗?还是所有列表都向上滑动,第一个元素将是第二个?示例:链表:

4
5
6
8

删除 4 后,列出它将是

null
5
6
8

或者 ?

5
6
8
4

2 回答 2

1

不会有“空白空间”,不会nullList<E>这是Java Collections API 中所有列表 ( ) 的通用约定。

于 2013-08-18T18:29:13.417 回答
0

这是它的代码。您必须在 IDE 中附加源代码。

 private E remove(Entry<E> e) {
    if (e == header)
        throw new NoSuchElementException();

        E result = e.element;
    e.previous.next = e.next;
    e.next.previous = e.previous;
        e.next = e.previous = null;
        e.element = null;
    size--;
    modCount++;
        return result;
    }

我希望你明白它的逻辑

于 2013-08-18T18:31:40.650 回答