链表是数据结构中存储数据的一种形式。分为单向链表和双向链表以及循环链表。LinkedList是泛型链表,用节点存取,节点类型为LinkedListNode<T>,每个节点都有Next和Previous属性,这就说明LinkedList是双向链表。链表的优点就是节省内存空间,每个节点包括两部分:数据域和指针域。每个节点相连,添加几个节点就占用几个节点的内存。

初始化:

LinkedList<int> intList = new LinkedList<int>();

添加一个新值到链表的开始:

intList.AddFirst(1);

添加一个新值到链表的结尾:

intList.AddLast(1);

获取第一个节点:

LinkedListNode<int> firstNode = intList.First;

获取最后一个节点:

LinkedListNode<int> lastNode = intList.Last;

在最后一个节点插入一个新值:

intList.AddBefore(lastNode, 3);

判断一个值是否存在:

intList.Contains(1);

查找指定值所在的节点:

LinkedListNode<int> node = intList.Find(1);

移除一个指定的值:

bool b = intList.Remove(1);

删除最开始的节点:

intList.RemoveFirst();

删除最后的节点:

intList.RemoveLast();

获取链表的节点数:

int count = intList.Count;

遍历链表:

foreach (var item in intList)
{
    //TODO Something
}

linked lists in .NET的更多相关文章

  1. [LeetCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  2. 【leetcode】Intersection of Two Linked Lists

    题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...

  3. [LintCode] Intersection of Two Linked Lists 求两个链表的交点

    Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...

  4. Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  5. Leetcode 160. Intersection of two linked lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  6. (LinkedList)Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  7. Java for LeetCode 160 Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

  8. [leetCode][003] Intersection of Two Linked Lists

    [题目]: Write a program to find the node at which the intersection of two singly linked lists begins. ...

  9. LeetCode Intersection of Two Linked Lists

    原题链接在这里:https://leetcode.com/problems/intersection-of-two-linked-lists/ 思路:1. 找到距离各自tail 相同距离的起始List ...

  10. 160. Intersection of Two Linked Lists

    Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...

随机推荐

  1. ajaxSetup设置Ajax请求的默认值

    ajaxSetup() 方法为将来的 AJAX 请求设置默认值.语法$.ajaxSetup({name:value, name:value, ... }) 该参数为带有一个或多个名称/值对的 AJAX ...

  2. Requests模块 HTTP for Humans

    安装方式 $ pip install requests 基本GET请求(headers参数 和 parmas参数) 1.最基本的GET请求可以直接用get方法 response = requests. ...

  3. 「mysql优化专题」90%程序员面试都用得上的索引优化手册(5)

    目录(技术文) 多关于索引,分为以下几点来讲解: 一.索引的概述(什么是索引,索引的优缺点) 二.索引的基本使用(创建索引) 三.索引的基本原理(面试重点) 四.索引的数据结构(B树,hash) 五. ...

  4. Android系统拍照之后回显并且获取文件路径

    /*调用拍照返回*/ case PHOTO_REQUEST_GALLERY: if (data != null) { Uri uri = data.getData(); String photopat ...

  5. JavaScript中函数function fun(){}和 var fun=function(){}的区别

    function fun(){} 和 var fun=function(){}的区别 标题有点长···· 废话少说,其实他们的主要区别就是"函数声明的提前行为". var fun= ...

  6. docker入门【1】

    1.拉取镜像 docker pull 镜像名:版本号 例如:docker pull tomcat:7.0 默认会从docker官方镜像库拉取,不指定版本的话版本为latest 拉取后docker im ...

  7. SpringMVC 返回json的两种方式

    前后台数据交互使用json是一种很重要的方式.本文主要探讨SpringMVC框架使用json传输的技术. 请注意,本文所提到的项目使用Spring 版本是4.1.7,其他版本在具体使用上可能有不一样的 ...

  8. 506. Relative Ranks

    Given scores of N athletes, find their relative ranks and the people with the top three highest scor ...

  9. vue-router项目实战总结

    今天来谈谈vue项目{vue,vue-router,component}三大神将之一的vue-router.作为我们前后端分离很重要的实践之一,router帮我们完成了SPA应用间的页面跳转. 并且, ...

  10. jquery $.fn $.fx是什么意思有什么用

    $.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效, .fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效. 如扩展$.fn ...