## 集合框架之链表集合算法 原

凯哥学堂

# 链表集合算法：
1.链=引用
2.链表集合与数组集合的区别：在增值方面，数组集合的速度比链表集合算法【学Java，到凯哥学堂kaige123.com】的速度要快；但是链表集合在增删值和修改值方面要更灵活，它的原理就好比链条。
3.链表的分类：
3.1单链集合（了解即可）：上家能找到下家，但是下家找不到上家，即通过上一个数组可以找到下一个数组，但是没办法通过下一个数组找到上一个数组。如下图：

![image](http://os78f4hny.bkt.clouddn.com/201707270001.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

3.2双链集合：上家能找到下家，下家也能找到上家。如下图：

![image](http://os78f4hny.bkt.clouddn.com/201707270002.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

4.代码实现（以双链为例）：
4.1添加值

![image](http://os78f4hny.bkt.clouddn.com/201707270003.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

![image](http://os78f4hny.bkt.clouddn.com/201707270004.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

![image](http://os78f4hny.bkt.clouddn.com/201707270005.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

![image](http://os78f4hny.bkt.clouddn.com/201707270006.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

4.2在头部添加值

![image](http://os78f4hny.bkt.clouddn.com/201707270007.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

4.3在尾部增加值

![image](http://os78f4hny.bkt.clouddn.com/201707270008.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

4.4删除第一个值

![image](http://os78f4hny.bkt.clouddn.com/201707270009.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

4.5删除最后一个值

![image](http://os78f4hny.bkt.clouddn.com/201707270010.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

4.6在指定的位置添加值

![image](http://os78f4hny.bkt.clouddn.com/201707270011.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)
![image](http://os78f4hny.bkt.clouddn.com/201707270012.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

4.7按下标删除值

![image](http://os78f4hny.bkt.clouddn.com/201707270013.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)
![image](http://os78f4hny.bkt.clouddn.com/201707270014.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

4.8对删除操作的改进版本：在执行删除操作时，可以返回被删除的值

![image](http://os78f4hny.bkt.clouddn.com/201707270015.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

![image](http://os78f4hny.bkt.clouddn.com/201707270016.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

![image](http://os78f4hny.bkt.clouddn.com/201707270017.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

![image](http://os78f4hny.bkt.clouddn.com/201707270018.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

5.用途：链表集合多用于队列模式，任务排队一系列的操作中。以队列模式为例：排队的好处【学Java，到凯哥学堂kaige123.com】就是先来的先取出执行，如下图，可以前面取值，后面进值，当然也可以后出前进

![image](http://os78f4hny.bkt.clouddn.com/201707270019.jpg?imageMogr2/blur/1x0/quality/75|watermark/1/image/aHR0cDovL29zNzhmNGhueS5ia3QuY2xvdWRkbi5jb20vd2F0ZXJtYXJrLnBuZw==/dissolve/50/gravity/SouthEast/dx/10/dy/10|imageslim)

### 凯哥学堂

Java核心技术卷1: 集合

fzyz_sb
2016/07/10
47
0

2017/09/11
0
0
java 集合框架－－基本概念

java 集合框架： 1. 什么是框架：类库的集合 2. 集合框架：用来表示和操作的统一的框架，包含了实现集合的接口与类 3. 集合：存放数据的容器。集合框架包含了两部分：一部分是接口，一部分是...

viewsonic001
2016/08/18
16
0

2018/08/04
0
0

ccj_ok
2017/09/14
0
0

19.1 Linux监控平台介绍 19.2 zabbix监控介绍 19.3/19.4/19.6 安装zabbix 19.5 忘记Admin密码如何做 19.1 Linux监控平台介绍： 常见开源监控软件 ~1.cacti、nagios、zabbix、smokeping、ope...

oschina130111

10
0

7
0
DNS-over-HTTPS 的下一代是 DNS ON BLOCKCHAIN

6
0
CC攻击带来的危害我们该如何防御？

11
0

8
0