Skip to content

Commit 9bdb713

Browse files
author
Naupio Z.Y. Huang
committed
update linked-list section (#289)
* add vector-string section in new quickstart * add io-stream on new quickstart chapter * update readme * update io-stream on quickstart * update introduction on quickstart * add quickstart.md * update summary * update instroduction section on quickstart chapter * update quickstart chapter * update binaryry-tree section * update graph section * update linked-list section
1 parent d666ea1 commit 9bdb713

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

data-structure/linked_list.md

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
# 33-05-data-struct-linked_list
1+
# 链表
22

3-
tags: RustPrimer
4-
5-
----------------
6-
7-
## 链表
3+
## 链表简介
84
链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态生成。每个结点包括两个部分:一个是存储数据元素的数据域,另一个是存储下一个结点地址的指针域。 相比于线性表顺序结构,操作复杂。由于不必须按顺序存储,链表在插入的时候可以达到O(1)的复杂度,比另一种线性表顺序表快得多,但是查找一个节点或者访问特定编号的节点则需要O(n)的时间,而线性表和顺序表相应的时间复杂度分别是O(logn)和O(1)。
95

106
>使用链表结构可以克服数组链表需要预先知道数据大小的缺点,链表结构可以充分利用计算机内存空间,实现灵活的内存动态管理。但是链表失去了数组随机读取的优点,同时链表由于增加了结点的指针域,空间开销比较大。链表最明显的好处就是,常规数组排列关联项目的方式可能不同于这些数据项目在记忆体或磁盘上顺序,数据的存取往往要在不同的排列顺序中转换。链表允许插入和移除表上任意位置上的节点,但是不允许随机存取。链表有很多种不同的类型:单向链表,双向链表以及循环链表。
117
128
下面看我们一步步实现链表:
139

14-
* 定义链表结构
10+
## 定义链表结构
1511

1612
```rust
1713
use List::*;
@@ -24,7 +20,7 @@ enum List {
2420
}
2521
```
2622

27-
* 实现链表的方法
23+
## 实现链表的方法
2824
```rust
2925
impl List {
3026
// 创建一个空链表
@@ -69,7 +65,7 @@ impl List {
6965
}
7066
```
7167

72-
* 代码测试
68+
## 代码测试
7369
```rust
7470
fn main() {
7571
let mut list = List::new();
@@ -83,7 +79,7 @@ fn main() {
8379
}
8480
```
8581

86-
* 练习
82+
## 练习
8783

8884
基于以上代码实现一个双向循环链表。
8985

0 commit comments

Comments
 (0)