LinkedList vs List
- 论坛
- LinkedList vs List<T>
25 浏览
LinkedList vs List
这个问题已经有了答案:
如果我预计不会使用索引访问我的数据结构,使用LinkedList比List节省多少?
如果我不确定是否会使用索引访问,我想知道差异。
假设我有N个实例。在链表中插入和删除只需要o(1)的操作,而在列表中可能需要O(n)的操作,但由于它被优化了,因此知道一些值的差异会很好。
例如,当N = 1,000,000和N = 1,000,000,000时。
admin 更改状态以发布 2023年5月21日
匿名的
0 Comments
List
仅仅是一个Array的装饰器。 LinkedList
只有在访问顺序数据(向前或向后)时才最有效率。
链表提供非常快速的列表成员插入或删除。链表中的每个成员都包含指向列表中下一个成员的指针,因此要在位置i上插入成员:
update the pointer in member i-1 to point to the new member set the pointer in the new member to point to member i