linked lists in .NET
链表是数据结构中存储数据的一种形式。分为单向链表和双向链表以及循环链表。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的更多相关文章
- [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 ...
- 【leetcode】Intersection of Two Linked Lists
题目简述: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- [LintCode] Intersection of Two Linked Lists 求两个链表的交点
Write a program to find the node at which the intersection of two singly linked lists begins. Notice ...
- Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- 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 ...
- (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 ...
- 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 ...
- [leetCode][003] Intersection of Two Linked Lists
[题目]: Write a program to find the node at which the intersection of two singly linked lists begins. ...
- LeetCode Intersection of Two Linked Lists
原题链接在这里:https://leetcode.com/problems/intersection-of-two-linked-lists/ 思路:1. 找到距离各自tail 相同距离的起始List ...
- 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 ...
随机推荐
- [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)
The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 11978 A ...
- 開始:触摸MySQL
学习MySQL.少不了安装一个MySQL数据库,安装想必非常easy,事实上也是.我下载了一个MySQL5.7.百度了一下安装步骤,就成功安装了.相对于Oracle来说要简单不少. 买了两本书,看了& ...
- Java的流程控制结构,细节详解
位运算符 &与 |或 ^异或 <<左移 >>右移 >>>无符号右移 ~取反 注意:位运算是针对整数运算的 int i = 6,j = 10; 方式一 ...
- 分享一个开源免费、目前最好的API接口管理平台----eoLinker
一.概况 eoLinker 是目前业内领先.国内最大的在线 API 接口管理平台,提供自动生成 API 文档.API 自动化测试.Mock 测试.团队协作等功能,旨在解决由于前后端分离导致的开发效率低 ...
- Aop介绍及几种实现方式
Aop介绍 我们先看一下wiki百科的介绍 Traditional software development focuses on decomposing systems into ...
- IEEE1588协议简介
IEEE1588协议,又称PTP(precise time protocol,精确时间协议),可以达到亚微秒级别时间同步精度,于2002年发布version1,2008年发布version2. IEE ...
- 【java】Vector
package com.tn.collect; import java.util.Enumeration; import java.util.Iterator; import java.util.Ve ...
- Python进阶之迭代器和生成器
可迭代对象 Python中任意的对象,只要它定义了可以返回一个迭代器的__iter__方法,或者定义了可以支持下标索引的__getitem__方法,那么它就是一个可迭代对象.简单来说,可迭代对象就是能 ...
- Intellij IDEA 像eclipse那样给maven添加依赖
打开pom.xml,在它里面使用快捷键:ALT+Insert ---->点击dependency 再输入想要添加的依赖关键字,比如:输个spring 出现下图: 根据需求选择版本,完成以后 ...
- vs2015企业版密钥
专业版:HMGNV-WCYXV-X7G9W-YCX63-B98R2 企业版:HM6NR-QXX7C-DFW2Y-8B82K-WTYJV