-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d70eee
commit 5e74127
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# 栈和队列 | ||
|
||
三要素: | ||
|
||
1. 逻辑结构 | ||
2. 数据的运算 | ||
3. 存储结构(物理结构) | ||
|
||
## 1. 栈 | ||
|
||
### 1.1. 定义 | ||
|
||
栈是**只允许在一端进行插入或删除操作**的线性表。 | ||
|
||
- 栈顶:允许插入和删除的一端。 | ||
- 栈底:不允许插入和删除的一端。 | ||
- 空栈 | ||
- 栈顶元素 | ||
- 栈底元素 | ||
|
||
进栈顺序: | ||
|
||
$$ | ||
a_1->a_2->a_3->a_4->a_5 | ||
$$ | ||
|
||
出栈顺序: | ||
|
||
$$ | ||
a_5->a_4->a_3->a_2->a_1 | ||
$$ | ||
|
||
后进先出,Last In First OUT(LIFO) | ||
|
||
### 1.2. 基本操作 | ||
|
||
- `InitStack(&S)`:初始化栈。构造一个空栈 $S$,分配内存空间。 | ||
- `DestroyStack(&S)`:销毁栈。销毁并释放栈 $S$ 所占用的内存空间。 | ||
- `Push(&S, x)`:进栈。若栈 $S$ 未满,则将 $x$ 加入使之成为新栈顶。 | ||
- `Pop(&S, &x)`:出战,若栈 $S$ 非空,则弹出栈顶元素,并用 $x$ 返回。 | ||
- `GetTop(S, &x)`:读栈顶元素。若栈 $S$ 非空,则用 $x$ 返回栈顶元素。 | ||
- `StackEmpty(S)`:判断一个栈 $S$ 是否为空。若 $S$ 为空,则返回 `true`,否则返回 `false`。 | ||
|
||
$n$ 个不同的元素进栈,出栈元素的不同排列的个数为: | ||
|
||
$$ | ||
\frac{1}{n+1} C^{n}_{2n} | ||
$$ | ||
|
||
上述公式称为 卡特兰(Catalan)数。可采用数学归纳法证明(不要求掌握)。 | ||
|
||
$$ | ||
\frac{1}{5+1} C^{5}_{10} | ||
=\frac{10*9*8*7*6}{6*5*4*3*2*1} | ||
=42 | ||
$$ | ||
|
||
### 1.3. 顺序栈 | ||
|
||
### 1.4. 链式栈 |