T>名单℃之间的差异;和LinkedList< T> [英] Difference between List<T> and LinkedList<T>

查看:103
本文介绍了T>名单℃之间的差异;和LinkedList< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们用列表,每当我们需要一个列表。我现在有一个LinkedList的注意。

We use List whenever we need a list. I notice now that there is a LinkedList.

我想知道是什么这两个之间的区别,什么时候应该使用一个比其他。

I was wondering what was the difference between these 2, and when you should use one over the other.

推荐答案

好了,列表< T> 基本上是由一个数组,通常比更大的支持目前的一些项目。元素被置于一个阵列,并且当旧用完空间中创建一个新的数组。这是快速通过索引访问,但在缓慢取出或插入列表中或在开始元素。 。添加/在列表的末尾删除条目是相当便宜。

Well, List<T> is basically backed by an array which is usually bigger than the current number of items. The elements are put in an array, and a new array is created when the old one runs out of space. This is fast for access by index, but slow at removing or inserting elements within the list or at the start. Adding/removing entries at the end of the list is reasonably cheap.

的LinkedList< T> 是一个doubly-链表 - 每个节点都知道它以前的条目及其下一个。这是快后插入/特定节点(或头/尾)之前,但慢于通过索引访问

LinkedList<T> is a doubly-linked list - each node knows its previous entry and its next one. This is fast for inserting after/before a particular node (or the head/tail), but slow at access by index.

的LinkedList< T> ; 一般的时间比更多的内存列表< T> ,因为它需要所有的下一首/上引用空间 - 并且数据将可能有参考较少局部性,因为每个节点都是一个单独的对象。在另一方面,列表< T> 可以的有一个支持数组比其当前需要更大

LinkedList<T> will usually take more memory than List<T> because it needs space for all those next/previous references - and the data will probably have less locality of reference, as each node is a separate object. On the other hand, a List<T> can have a backing array which is much larger than its current needs.

这篇关于T&GT;名单℃之间的差异;和LinkedList&LT; T&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆