1.循环链表:
![](https://img-blog.csdnimg.cn/img_convert/4756f581314d0dd9128e60f37c0e773d.png)
优点:从表中任何一个结点出发均可找到表中其他结点。
判断是否到底尾结点(即需要判断是否完全遍历了一遍):判断是否等于头指针
![](https://img-blog.csdnimg.cn/img_convert/25224059bb428bfb6c79205c284fb999.png)
通常用尾指针去操作循环链表:
![](https://img-blog.csdnimg.cn/img_convert/4a9550907ec8842d231eab4eb6b8e152.png)
合并两个带尾指针的循环链表:
![](https://img-blog.csdnimg.cn/img_convert/00f2871cd33440e742e860e3932d50f2.png)
![](https://img-blog.csdnimg.cn/img_convert/21b9fc2e41b55dbad1c07b7d4358b4eb.png)
2.双向链表:[prior][data][next]
![](https://img-blog.csdnimg.cn/img_convert/02a0c6229b32a3f1bbdd2ea8a9649dab.png)
![](https://img-blog.csdnimg.cn/img_convert/3edb73c67d90f262aef689e5a4240bad.png)
双向链表也有循环表:双向循环链表
![](https://img-blog.csdnimg.cn/img_convert/54e9a9b2a4a3d5ca94f41c6a55e47dea.png)
双向链表具有对称性,即p可以通过前趋的后继找到,也可以通过后继的前趋找到。
![](https://img-blog.csdnimg.cn/img_convert/d783ab822aef730c26d37a7f2a2bfd1d.png)
1)双向链表的插入:
![](https://img-blog.csdnimg.cn/img_convert/e2e9c1eba901beda24e2e22cd1a31cd0.png)
![](https://img-blog.csdnimg.cn/img_convert/2650e05beefade3922e98b21b4a61014.png)
2)双向链表的删除:
![](https://img-blog.csdnimg.cn/img_convert/5c993832d89f756322daaeefbbebd612.png)
![](https://img-blog.csdnimg.cn/img_convert/aacd96dfd9b088939a5049877b48f32b.png)
双向链表的思路:想清楚插入和删除示意图,弄清楚前趋后继是什么即可。
3.三种链表的时间复杂度的比较:
![](https://img-blog.csdnimg.cn/img_convert/4983eb4c2deddc512c15660abb28df80.png)
4.顺序表和链表的比较:
链式优点:1.结点空间可以动态申请和释放;
2.逻辑次序靠指针实现,故而插入和删除时不需要移动数据元素。
链式缺点:1.存储密度较小,每个结点的指针域需要额外占用空间,因而有时指针域占更大的比重;
2.链式存储是非随机存取,对任意结点都要从头/尾开始,增加了算法复杂度。
顺序表和链表的比较:各有优劣,根据实际情况进行合理选择:
![](https://img-blog.csdnimg.cn/img_convert/b9849af1dfebd77e597b5e49b018a75b.png)
5.线性表的两个简单应用
![](https://img-blog.csdnimg.cn/img_convert/b44f2d8c8f68659ebb6f8f91faab003a.png)
1)线性表的合并:
![](https://img-blog.csdnimg.cn/img_convert/519792afeef9c1958881c70eee47389a.png)
注意没有说明选择顺序表还是链表,需要结合实际情况进行分析。
该算法的时间复杂度是: O(ListLength(La)*ListLength(Lb))
2)有序表的合并(用顺序表实现):
![](https://img-blog.csdnimg.cn/img_convert/82a3ea32e1785d9ca3cd83ba393788b8.png)
注意多设置了两个指针指向两个表的最后一个结点,用来判断是否结束;
![](https://img-blog.csdnimg.cn/img_convert/e3c570b6ef68b392df07100de34963a5.png)
算法的时间复杂度是:O(ListLength(La)+ListLength(Lb));
算法的空间复杂度是: O(ListLength(La)+ListLength(Lb))。
3)有序表的合并(用链表实现):
![](https://img-blog.csdnimg.cn/img_convert/42d7f41ccb05bf351103f8225369f528.png)
其中这一句的意思是把还有剩余的链表接到c后面:
![](https://img-blog.csdnimg.cn/img_convert/daa675dcdf6c62a44df49322595b2b35.png)
算法的时间复杂度是:O(ListLength(La)+ListLength(Lb));
算法的空间复杂度是: O(1)。
6.线性表的案列的思路分析
1)一元多项式的运算:实现两个多项式加、减、乘运算
线性表如何表示多项式:
![](https://img-blog.csdnimg.cn/img_convert/441362d54faa55794ab7142e4bc23952.png)
则实现两个多项式的运算:用顺序表来实现,其实就是数组相加/减/乘:
![](https://img-blog.csdnimg.cn/img_convert/77e53c5a78364a8a646cdb638d36582d.png)
2)稀疏多项式的运算:
![](https://img-blog.csdnimg.cn/img_convert/01edd1306c6d9f140ce2638420cd8d36.png)
a.利用顺序表实现的思路:
![](https://img-blog.csdnimg.cn/img_convert/16e43bcec38c58cf2c9fbd11a64d12b0.png)
两个问题:1.需要新数组C导致空间复杂度高 2.未知数组C的大小
b.利用链表实现的思路:
![](https://img-blog.csdnimg.cn/img_convert/57e1805edb05a3546e73e13813581cbf.png)
![](https://img-blog.csdnimg.cn/img_convert/b8867b5761a6b7430fe80541517f0a53.png)
![](https://img-blog.csdnimg.cn/img_convert/f7b97acc0773d931a7179077cac1017b.png)
![](https://img-blog.csdnimg.cn/img_convert/600c93b07f07e31d7285b3373fe42d93.png)
3)图书信息管理系统:
图书变量不大:顺序表; 图书变量很大,即经常插入或删除:链表:
![](https://img-blog.csdnimg.cn/img_convert/f9cfcf1155f3e048e93a8d9fbcd71a05.png)
![](https://img-blog.csdnimg.cn/img_convert/43319cd3a0240cc2ec12cde3d74cc08e.png)
定义好之后利用两个表已经学过的查找、插入、删除等操作即可。