C#LinkedList<T>链表

C#链表

一、基本概念

链表在很多语言中都有介绍,它是一种链状的数据结构。它本身带有的节点可以指向下一个或上一个节点,从而可实现轮询。
在这里插入图片描述

二、链表的优缺点

优点:
一般数组都是需要一连串的内存空间来存储数据,但是链表结构不需要一连串的内存空间。此外,由于他具有的独特的结构,使得链表插入数据变得非常的快捷。因为它不需要移动后面的数据。List列表中间插入一个数据时,后面所有的数据都要进行移动。

缺点:
但是链表也有缺点,因为每个节点都是离散的,所以访问链表中数据只能一个接着一个访问,这需要较长的时间来查找位于链表中间或尾部的元素。访问数据效率就会变得低下。

三、LinkedList<T>

是一个双向的链表,其元素指定前面和后面的元素。

public class LinkedList : ICollection<T>, IEnumerable<T>, ICollection, IEnumerable, ISerializable, IDeserializationCallback
{ 类体。。。}

上述可知,LinkedList<T>继承了ICollection, IEnumerable<T>, ICollection, IEnumerable, ISerializable, IDeserializationCallback接口。

四、LinkedList<T>链表常用的方法

// 摘要: 
//     初始化为空的 System.Collections.Generic.LinkedList<T> 类的新实例。
public LinkedList();
//
// 摘要: 
//     初始化 System.Collections.Generic.LinkedList<T> 类的新实例,该实例包含从指定的 System.Collections.IEnumerable
//     中复制的元素并且其容量足以容纳所复制的元素数。
//
// 参数: 
//   collection:
//     System.Collections.IEnumerable,其元素被复制到新的 System.Collections.Generic.LinkedList<T>
//     中。
//
// 异常: 
//   System.ArgumentNullException:
//     collection 为 null。
public LinkedList(IEnumerable<T> collection);
//
// 摘要: 
//     初始化 System.Collections.Generic.LinkedList<T> 类的新实例,该实例可使用指定的 System.Runtime.Serialization.SerializationInfo
//     和 System.Runtime.Serialization.StreamingContext 进行序列化。
//
// 参数: 
//   info:
//     一个 System.Runtime.Serialization.SerializationInfo 对象,它包含序列化 System.Collections.Generic.LinkedList<T>
//     所需的信息。
//
//   context:
//     System.Runtime.Serialization.StreamingContext 对象,该对象包含与 System.Collections.Generic.LinkedList<T>
//     相关联的序列化流的源和目标。
protected LinkedList(SerializationInfo info, StreamingContext context);

// 摘要: 
//     获取 System.Collections.Generic.LinkedList<T> 中实际包含的节点数。
//
// 返回结果: 
//     System.Collections.Generic.LinkedList<T> 中实际包含的节点数。
public int Count {
    get; }
//
// 摘要: 
//     获取 System.Collections.Generic.LinkedList<T> 的第一个节点。
//
// 返回结果: 
//     System.Collections.Generic.LinkedList<T> 的第一个 System.Collections.Generic.LinkedListNode<T>。
public LinkedListNode<T> First {
    get; }
//
// 摘要: 
//     获取 System.Collections.Generic.LinkedList<T> 的最后一个节点。
//
// 返回结果: 
//     System.Collections.Generic.LinkedList<T> 的最后一个 System.Collections.Generic.LinkedListNode<T>。
public LinkedListNode<T> Last {
    get; }

// 摘要: 
//     在 System.Collections.Generic.LinkedList<T> 中指定的现有节点后添加指定的新节点。
//
// 参数: 
//   node:
//     要在其后插入 newNode 的 System.Collections.Generic.LinkedListNode<T>。
//
//   newNode:
//     要添加到 System.Collections.Generic.LinkedList<T> 的新 System.Collections.Generic.LinkedListNode<T>。
//
// 异常: 
//   System.ArgumentNullException:
//     node 为 null。 - 或 - newNode 为 null。
//
//   System.InvalidOperationException:
//     node 不在当前 System.Collections.Generic.LinkedList<T> 中。 - 或 - newNode 属于另一个
//     System.Collections.Generic.LinkedList<T>。
public void AddAfter(LinkedListNode<T> node, LinkedListNode<T> newNode);
//
// 摘要: 
//     在 System.Collections.Generic.LinkedList<T> 中指定的现有节点后添加包含指定值的新节点。
//
// 参数: 
//   node:
//     要在其后插入包含 value 的新 System.Collections.Generic.LinkedListNode<T> 的 System.Collections.Generic.LinkedListNode<T>。
//
//   value:
//     要添加到 System.Collections.Generic.LinkedList<T> 的值。
//
// 返回结果: 
//     包含 value 的新 System.Collections.Generic.LinkedListNode<T>。
//
// 异常: 
//   System.ArgumentNullException:
//     node 为 null。
//
//   System.InvalidOperationException:
//     node 不在当前 System.Co
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值