c# - List<T> 是链表吗?

标签 c# .net

System.Collections.Generic.List<T>一种 linked list (不是 LinkedList<T> 类)

A linked list is a data structure consisting of a group of nodes which together represent a sequence. Under the simplest form, each node is composed of a datum and a reference (in other words, a link) to the next node in the sequence.

Linear Linked List
A linked list whose nodes contain two fields: an integer value and a link to the next node.
The last node is linked to a terminator used to signify the end of the list.

wikipedia.org

如果是,它是什么样的链表?

最佳答案

不, List<T> 由数组支持 - 它本质上是 ArrayList 的通用版本来自.NET 1.0。来自文档:

The List<T> class is the generic equivalent of the ArrayList class. It implements the IList<T> generic interface using an array whose size is dynamically increased as required.

请注意,由于由数组支持,它通过索引器的访问是 O(1) 而不是链表的 O(N)。

如果你想要一个链表,使用 LinkedList<T> .请注意,这是一个双向链表。我不相信 .NET 会公开链表类型。

关于c# - List<T> 是链表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9971916/

相关文章:

c# - 在运行时移动控制

c# - Controller 中的 "The entity or complex type cannot be constructed in a LINQ to Entities query"

c# - unity3d - 如何从 C# 脚本创建地形

c# - 如何检测证书的类型(A1 或 A3)?

.net - 我可以在 App.config 中声明和使用 DTD 实体吗?

.net - 通用字典并为多部分键生成哈希码

c# - 使用对象初始化时如何获取父类(即初始化当前类的类)的实例?

c# - 异步使用 System.Diagnostics.Process,我应该如何确保在确定它已退出之前收到最后的输出?

c# - 带有按钮 "Yes to All"和 "No to All"的消息框

c# - 学习 System.Speech API 的好资源是什么?