问题描述
java中实现单双链表哪个集合接口效率高?代码示例好吗?
Which collection interface is efficient to implement the singly and doubly linked list in java? code sample please?
推荐答案
毫无疑问,实现双向链表的正确接口是 LinkedList.请参阅JavaDoc.
The right interface to implement a doubly-linked list is, unsurprisingly, a LinkedList. See the JavaDoc.
我不会在这里给你一个代码示例;它们遍布网络,您只需花两分钟的研究就能找到.
I'm not going to give you a code sample here; they're all over the web and you could find one with two minutes' research.
如果您出于某种原因想要一个单向链表,您可能不得不使用自定义 Node 类来创建自己的链表.每个节点应该只有一个数据对象和一个指向下一个节点的指针.
If you want a singly-linked list for some reason, you're probably going to have to roll your own using a custom Node class. Each Node should just have a data object and a pointer to the next Node.
这篇关于java中的单链表和双链表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!