简体   繁体   English

Java中的单双链表?

[英]singly and doubly linked list in java?

Which collection interface is efficient to implement the singly and doubly linked list in java? 哪个集合接口可以有效地在Java中实现单链和双链列表? code sample please? 代码样本好吗?

The right interface to implement a doubly-linked list is, unsurprisingly, a LinkedList. 毫无疑问,实现双向链接列表的正确接口是LinkedList。 See the JavaDoc . 参见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. 他们遍布网络,您只需花两分钟的时间就可以找到一个。

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. 如果出于某种原因想要单链列表,则可能必须使用自定义Node类来滚动自己的列表。 Each Node should just have a data object and a pointer to the next Node. 每个节点应该只具有一个数据对象和一个指向下一个节点的指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM