[英]Why does ListIterator provide an index for elements in a LinkedList?
Unlike an ArrayList, a LinkedList can not access an element at a particular point using an index. 与ArrayList不同,LinkedList无法使用索引在特定点访问元素。
If this is the case, then what is the point of the ListIterator providing functionality that returns the index of a particular point in a LinkedList? 如果是这种情况,那么ListIterator的点是什么,该点提供了可返回LinkedList中特定点的索引的功能?
Why would I ever need to know the index of a LinkedList, if I can't ever use it to access an element. 如果我永远无法使用LinkedList的索引访问元素,为什么还要知道它的索引。 Am I missing something here?
我在这里想念什么吗?
You can use get() for LinkedList, but it has O(n) time complexity so it can be inefficient in some situations. 您可以对LinkedList使用get(),但它的时间复杂度为O(n),因此在某些情况下可能效率很低。 But you can use element index for estimate order of elements in the list or something else depending of your needs.
但是您可以根据需要使用元素索引来估计列表中元素的顺序或其他方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.