[英]How would I go about returning the data from a specific node in a singly linked list?
Do I have to search for the node as a stack or queue, and when I find it set the data that the node returns equal to local variables? 我是否必须将节点搜索为堆栈或队列,并且在找到节点时将节点返回的数据设置为等于局部变量?
Or is there a way of calling a known position in the list, like how you can with an array. 或者有没有一种方法可以调用列表中的已知位置,例如如何使用数组。
Visually what I'm asking here is: 视觉上我在这里问的是:
So how Arrays work like this: 因此, 数组的工作方式如下:
ArrayofStrings[Postion] returns String located at Position
Is there a way to do the same with a Linked List like this? 有没有办法对像这样的链表做同样的事情?
SinglyLinkedList(Node) returns Multiple(string) Data(double)
I'm guessing I have to search the list for the node, but I wanted to make sure there wasn't an easier way to do this. 我猜想我必须在列表中搜索该节点,但是我想确保没有更简单的方法可以做到这一点。
java中的所有列表都提供get的实现,该实现返回list中的第n个元素。
LinkedLists pros and cons LinkedList的优缺点
pros 优点
cons 缺点
Arrays pros and cons. 数组的优缺点。
pros 优点
cons 缺点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.