Java中是否有任何双向链表实现?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31365998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any doubly linked list implementation in Java?
提问by Avinash Jethy
I see JDK implementation of LinkedList
internally contains Node
inner class, which contains the address to next and previous.
我看到LinkedList
内部包含Node
内部类的JDK实现,其中包含下一个和上一个的地址。
So my doubt isn't LinkedList
in java a doubly linked list. If not, why?
所以我怀疑LinkedList
在java中不是双向链表。如果不是,为什么?
And how to implement our own doubly linked list?
以及如何实现我们自己的双向链表?
采纳答案by Eran
Yes, LinkedList
is a doubly linked list, as the Javadoc mentions :
是的,LinkedList
是一个双向链表,正如 Javadoc 提到的:
Doubly-linked list implementationof the List and Deque interfaces. Implements all optional list operations, and permits all elements (including null).
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.
List 和 Deque 接口的双向链表实现。实现所有可选的列表操作,并允许所有元素(包括空值)。
所有操作的执行都符合双向链表的预期。索引到列表中的操作将从开头或结尾遍历列表,以更接近指定索引的为准。