问题描述
我看到 LinkedList
的JDK实现内部包含 Node
内部类,该内部类包含下一个和上一个的地址.
I see JDK implementation of LinkedList
internally contains Node
inner class, which contains the address to next and previous.
因此,我怀疑Java中的 LinkedList
不是双向链接列表.如果没有,为什么?
So my doubt isn't LinkedList
in java a doubly linked list. If not, why?
以及如何实现我们自己的双向链表?
And how to implement our own doubly linked list?
推荐答案
是的, LinkedList
是一个双向链接列表,如Javadoc所述:
Yes, LinkedList
is a doubly linked list, as the Javadoc mentions :
所有操作均按双向链接列表的预期执行.索引到列表中的操作将从列表的开头或结尾开始遍历列表,以更接近指定索引的位置为准.
All of the operations perform as could be expected for a doubly-linked list. Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.
这篇关于Java中是否有双链表实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!