🎉 Init

This commit is contained in:
Kim Yang
2020-07-30 22:41:19 +08:00
parent 957440d0a2
commit f75fed12d9
231 changed files with 3461 additions and 1 deletions

View File

@@ -0,0 +1,194 @@
//
// Created by kim on 2020/6/21.
//
//顺序栈的实现
#include <stdio.h>
# define MaxSize 10
typedef struct {
int data[MaxSize];
int top;
} SqStack;
//初始化
void InitStack(SqStack &S) {
S.top = -1;//这种初始化的方式,栈顶指针始终指向栈顶元素
}
//初始化1
void InitStack1(SqStack &S) {
S.top = 0;//这种初始化方式,栈顶指针始终会指向栈顶元素的下一空元素
}
//入栈
bool Push(SqStack &S, int t) {
if (S.top == MaxSize - 1)return false;//栈满
S.data[++S.top] = t;
// 等价下面两个语句
// S.top+=1;//先将栈顶指针指向下一个位置
// S.data[S.top]=t;//再填充元素
return true;
}
//入栈初始化1
bool Push1(SqStack &S, int t) {
if (S.top == MaxSize)return false;//栈满,注意初始化条件不一样判空的条件也不一样了
S.data[S.top++] = t;
// 等价下面两个语句
// S.data[S.top]=t;
// S.top+=1;
//注意初始化方式不同,上边的顺序也不一样了,先填充元素,再移动指针
return true;
}
//出栈,并打印出栈顶元素
bool Pop(SqStack &S, int &x) {
//判断
if (S.top == -1)return false;//栈空报错
x = S.data[S.top--];
// 等价于下面
// x=S.data[S.top];//先取元素
// S.top -=1;//再改指针
return true;
}
//出栈,并打印出栈顶元素初始化1
bool Pop1(SqStack &S, int &x) {
//判断
if (S.top == 0)return false;//栈空报错,注意判空条件
x = S.data[--S.top];
// 等价于下面
// S.top -=1;
// x=S.data[S.top];
//注意初始化方式不同,上边的顺序也不一样了,先将指针指向当前栈顶元素,再将其取出
return true;
}
//读取栈顶元素
bool GetTop(SqStack S, int &x) {
if (S.top == -1)return false;
x = S.data[S.top];
return true;
}
//读取栈顶元素初始化1
bool GetTop1(SqStack S, int &x) {
if (S.top == 0)return false;
x = S.data[S.top-1];//注意按初始化1的方式这里指针减1才是栈顶元素的位置
// 同时注意不能使用--S.top,因为这里是读取,不可修改原栈,所以不可和出栈一样
//但即时这里你错误使用了--S.top也不会有问题因为此处的S是值传递非引用传递所以你修改的也只是复制之后的S不会影响原栈S即时这样也不建议使用--S.top如果老师较真的话可以扣分哒
return true;
}
//读取栈顶元素的第二种实现方式
//利用返回值返回栈顶元素,若成功就返回栈顶元素,失败就返回-1
//缺点:如果栈顶元素就是-1容易造成误判正因它的缺点如果考试考到了它写这种方式应该是会被扣部分分数的
int GetTopOther(SqStack S) {
if (S.top == -1)return -1;
return S.data[S.top];
}
int GetTopOther1(SqStack S) {
if (S.top == 0)return -1;
return S.data[S.top-1];
}
//打印整个栈
void PrintStack(SqStack S){
printf("从栈顶元素开始,栈如下:\n");
while (S.top>=0){//注意判空的条件
printf("S[%d]=%d\n",S.top,S.data[S.top--]);
}
printf("栈打印完毕\n");
}
//打印整个栈初始化方式1
void PrintStack1(SqStack S){
printf("从栈顶元素开始,栈如下:\n");
while (S.top>0){//注意判空的条件
printf("S1[%d]=%d\n",S.top-1,S.data[--S.top]);//初始化方式1得先移动指针再获取元素
}
printf("栈打印完毕\n");
}
void testStack() {
printf("开始测试\n");
SqStack S;
printf("测试第一种初始化方式\n");
InitStack(S);
if (Push(S,1)){
printf("入栈成功啦!\n");
} else{
printf("入栈失败了\n");
}
if (Push(S,2)){
printf("入栈又成功啦!\n");
} else{
printf("入栈又失败了\n");
}
PrintStack(S);
int x;
if (Pop(S, x)){
printf("出栈成功,弹出的元素为:%d\n",x);
} else{
printf("出栈失败了,再检出一下吧!\n");
}
PrintStack(S);
int x1;
if (GetTop(S,x1)){
printf("读取栈顶元素成功了,栈顶元素为:%d\n",x1);
}else{
printf("读取栈顶元素失败,再检查一下吧!\n");
}
int x4=GetTopOther(S);
if (x4!=-1){
printf("第二种读取栈顶元素的方式成功了,栈顶元素为:%d\n",x4);
} else{
printf("第二种读取栈顶元素的方式失败了\n");
}
printf("测试第二种初始化方式\n");
SqStack S1;
InitStack1(S1);
if (Push1(S1,1)){
printf("入栈成功啦!\n");
} else{
printf("入栈失败了\n");
}
if (Push1(S1,2)){
printf("入栈又成功啦!\n");
} else{
printf("入栈又失败了\n");
}
PrintStack1(S1);
int x2;
if (Pop1(S1, x2)){
printf("出栈成功,弹出的元素为[%d]\n",x2);
} else{
printf("出栈失败了,再检出一下吧!\n");
}
PrintStack1(S1);
int x3;
if (GetTop1(S1,x3)){
printf("读取栈顶元素成功了,栈顶元素为:%d\n",x3);
}else{
printf("读取栈顶元素失败,再检查一下吧!\n");
}
int x5=GetTopOther1(S1);
if (x5!=-1){
printf("第二种读取栈顶元素的方式成功了,栈顶元素为:%d\n",x5);
} else{
printf("第二种读取栈顶元素的方式失败了\n");
}
printf("测试完毕了!\n");
}
int main() {
printf("Hello, SqStack!");
testStack();
return 0;
}

View File

@@ -0,0 +1,160 @@
//
// Created by kim on 2020/6/28.
//
//共享顺序栈的实现
//简单来说就是两个栈共享一片存储空间,提高顺序栈的对存储空间的使用率
#include <stdio.h>
# define MaxSize 10
typedef struct {
int data[MaxSize];
int top0;
int top1;
} ShStack;
//从结构体的定义就可以看出来,两个共享栈的根源就在于定义两个指针
//初始化
void InitStack(ShStack &S) {
S.top0 = -1;//这种初始化的方式,栈顶指针始终指向栈顶元素
S.top1 =MaxSize;//这里的MaxSize就是所谓的第二个栈的栈底
//可以根据顺序栈的第二种初试化方式,思考一下这种共享顺序栈的第二种初始化方式
//S.top0=0
//S.top1=MaxSize-1
}
//入栈0
bool Push0(ShStack &S, int t) {
if (S.top0 +1== S.top1)return false;//注意共享栈满的条件
S.data[++S.top0] = t;//仔细品味一下这个++S.top
return true;
}
//入栈1
bool Push1(ShStack &S, int t) {
if (S.top0 +1== S.top1)return false;//注意共享栈满的条件
S.data[--S.top1] = t;//仔细品味一下这个--S.top想想为什么
return true;
}
//出栈,并打印出栈顶元素
bool Pop0(ShStack &S, int &x) {
//判断
if (S.top0 == -1)return false;//栈空报错
x = S.data[S.top0--];
// 等价于下面
// x=S.data[S.top];//先取元素
// S.top -=1;//再改指针
return true;
}
//出栈1
bool Pop1(ShStack &S, int &x) {
//判断
if (S.top1 == MaxSize)return false;//注意一下它的栈空报错条件
x = S.data[S.top1++];//注意这个栈修改指针是++
// 等价于下面
// x=S.data[S.top];//先取元素
// S.top +=1;//再改指针
return true;
}
//读取栈顶元素栈0
bool GetTop0(ShStack S, int &x) {
if (S.top0 == -1)return false;
x = S.data[S.top0];
return true;
}
//栈1
bool GetTop1(ShStack S, int &x) {
if (S.top1 == MaxSize)return false;
x = S.data[S.top1];
return true;
}
//打印整个栈,栈0
void PrintStack0(ShStack S){
printf("从栈顶元素开始,栈如下:\n");
while (S.top0>-1){//注意判空的条件
printf("S[%d]=%d\n",S.top0,S.data[S.top0--]);
}
printf("栈打印完毕\n");
}
//打印整个栈
void PrintStack1(ShStack S){
printf("从栈顶元素开始,栈如下:\n");
while (S.top1<MaxSize){//注意判空的条件
printf("S[%d]=%d\n",S.top1,S.data[S.top1++]);
}
printf("栈打印完毕\n");
}
void testShStack() {
printf("开始测试\n");
ShStack S;
InitStack(S);
printf("测试第一个栈\n");
if (Push0(S,1)){
printf("入栈成功啦!\n");
} else{
printf("入栈失败了\n");
}
if (Push0(S,2)){
printf("入栈又成功啦!\n");
} else{
printf("入栈又失败了\n");
}
PrintStack0(S);
int x;
if (Pop0(S, x)){
printf("出栈成功,弹出的元素为:%d\n",x);
} else{
printf("出栈失败了,再检出一下吧!\n");
}
PrintStack0(S);
int x1;
if (GetTop0(S,x1)){
printf("读取栈顶元素成功了,栈顶元素为:%d\n",x1);
}else{
printf("读取栈顶元素失败,再检查一下吧!\n");
}
printf("测试第一个栈\n");
if (Push1(S,10)){
printf("入栈成功啦!\n");
} else{
printf("入栈失败了\n");
}
if (Push1(S,9)){
printf("入栈又成功啦!\n");
} else{
printf("入栈又失败了\n");
}
PrintStack1(S);
int x3;
if (Pop1(S, x3)){
printf("出栈成功,弹出的元素为:%d\n",x3);
} else{
printf("出栈失败了,再检出一下吧!\n");
}
PrintStack1(S);
int x4;
if (GetTop1(S,x4)){
printf("读取栈顶元素成功了,栈顶元素为:%d\n",x4);
}else{
printf("读取栈顶元素失败,再检查一下吧!\n");
}
printf("测试完毕了!\n");
}
int main() {
printf("Hello, ShStack!");
testShStack();
return 0;
}

View File

@@ -0,0 +1,159 @@
//
// Created by kim on 2020/6/28.
//
//链栈的实现
#include <stdio.h>
# define MaxSize 10
typedef struct {
int data[MaxSize];
int top0;
int top1;
} ShStack;
//从结构体的定义就可以看出来,两个共享栈的根源就在于定义两个指针
//初始化
void InitStack(ShStack &S) {
S.top0 = -1;//这种初始化的方式,栈顶指针始终指向栈顶元素
S.top1 =MaxSize;//这里的MaxSize就是所谓的第二个栈的栈底
//可以根据顺序栈的第二种初试化方式,思考一下这种共享顺序栈的第二种初始化方式
//S.top0=0
//S.top1=MaxSize-1
}
//入栈0
bool Push0(ShStack &S, int t) {
if (S.top0 +1== S.top1)return false;//注意共享栈满的条件
S.data[++S.top0] = t;//仔细品味一下这个++S.top
return true;
}
//入栈1
bool Push1(ShStack &S, int t) {
if (S.top0 +1== S.top1)return false;//注意共享栈满的条件
S.data[--S.top1] = t;//仔细品味一下这个--S.top想想为什么
return true;
}
//出栈,并打印出栈顶元素
bool Pop0(ShStack &S, int &x) {
//判断
if (S.top0 == -1)return false;//栈空报错
x = S.data[S.top0--];
// 等价于下面
// x=S.data[S.top];//先取元素
// S.top -=1;//再改指针
return true;
}
//出栈1
bool Pop1(ShStack &S, int &x) {
//判断
if (S.top1 == MaxSize)return false;//注意一下它的栈空报错条件
x = S.data[S.top1++];//注意这个栈修改指针是++
// 等价于下面
// x=S.data[S.top];//先取元素
// S.top +=1;//再改指针
return true;
}
//读取栈顶元素栈0
bool GetTop0(ShStack S, int &x) {
if (S.top0 == -1)return false;
x = S.data[S.top0];
return true;
}
//栈1
bool GetTop1(ShStack S, int &x) {
if (S.top1 == MaxSize)return false;
x = S.data[S.top1];
return true;
}
//打印整个栈,栈0
void PrintStack0(ShStack S){
printf("从栈顶元素开始,栈如下:\n");
while (S.top0>-1){//注意判空的条件
printf("S[%d]=%d\n",S.top0,S.data[S.top0--]);
}
printf("栈打印完毕\n");
}
//打印整个栈
void PrintStack1(ShStack S){
printf("从栈顶元素开始,栈如下:\n");
while (S.top1<MaxSize){//注意判空的条件
printf("S[%d]=%d\n",S.top1,S.data[S.top1++]);
}
printf("栈打印完毕\n");
}
void testShStack() {
printf("开始测试\n");
ShStack S;
InitStack(S);
printf("测试第一个栈\n");
if (Push0(S,1)){
printf("入栈成功啦!\n");
} else{
printf("入栈失败了\n");
}
if (Push0(S,2)){
printf("入栈又成功啦!\n");
} else{
printf("入栈又失败了\n");
}
PrintStack0(S);
int x;
if (Pop0(S, x)){
printf("出栈成功,弹出的元素为:%d\n",x);
} else{
printf("出栈失败了,再检出一下吧!\n");
}
PrintStack0(S);
int x1;
if (GetTop0(S,x1)){
printf("读取栈顶元素成功了,栈顶元素为:%d\n",x1);
}else{
printf("读取栈顶元素失败,再检查一下吧!\n");
}
printf("测试第一个栈\n");
if (Push1(S,10)){
printf("入栈成功啦!\n");
} else{
printf("入栈失败了\n");
}
if (Push1(S,9)){
printf("入栈又成功啦!\n");
} else{
printf("入栈又失败了\n");
}
PrintStack1(S);
int x3;
if (Pop1(S, x3)){
printf("出栈成功,弹出的元素为:%d\n",x3);
} else{
printf("出栈失败了,再检出一下吧!\n");
}
PrintStack1(S);
int x4;
if (GetTop1(S,x4)){
printf("读取栈顶元素成功了,栈顶元素为:%d\n",x4);
}else{
printf("读取栈顶元素失败,再检查一下吧!\n");
}
printf("测试完毕了!\n");
}
int main() {
printf("Hello, ShStack!");
testShStack();
return 0;
}

View File

@@ -0,0 +1,24 @@
# 栈
![image-20200624150012426](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3e19r5y8j30u30d9whr.jpg)
## 栈的定义
![image-20200624150149844](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3e2xb551j30w90gl46s.jpg)
![image-20200624150313680](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3e4dmrd7j30tr0epn79.jpg)
![image-20200624150459308](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3e67blrmj30vl0e9n6m.jpg)
## 栈的基本操作
![image-20200624150704360](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3e8dd5asj30x30f7n5z.jpg)
### 出栈顺序
![image-20200624150927909](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3eavbxr9j30ra0fsdlo.jpg)
## 总结
![image-20200624151001874](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ebgf75pj30yv0fo452.jpg)

View File

@@ -0,0 +1,41 @@
# 顺序栈
![image-20200624151201362](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ediqo6gj30n70bvgpc.jpg)
## 顺序栈的定义
![image-20200624151329974](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ef24b97j30wx0hxgvy.jpg)
## 基本操作
### 初始化操作
![image-20200624151413408](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3eftbuugj30wr0i1qbi.jpg)
### 进栈操作
![image-20200624151826628](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ek7hcz7j30xn0icdsu.jpg)
### 出栈操作
![image-20200624152110685](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3en4wi18j30y70idgzs.jpg)
### 读取栈顶元素
![image-20200624152208184](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3eo1opjcj30xn0hjguw.jpg)
## 另一种基本操作的实现方式:
![image-20200624152341443](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3epo5wa6j30xn0fuwn2.jpg)
![image-20200624152540477](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3erqkql9j31090hrqg4.jpg)
## 共享栈
![image-20200624152655905](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3et1c5a6j30x60j4aib.jpg)
## 总结
![image-20200624152849214](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ev03gkaj30rs0g3aet.jpg)

View File

@@ -0,0 +1,18 @@
# 链栈
![image-20200624153019827](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ewkr8m8j30oj0e2770.jpg)
## 复习单链表
![image-20200624153122502](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3exnol1fj30wx0imgtj.jpg)
![image-20200624153252888](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ez8ce1ej30tn0drgrc.jpg)
## 链栈的定义
![image-20200624153433781](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3f0zi9tij30vr0gqn36.jpg)
## 总结
![image-20200624153535956](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3f222idsj30sc0e5tcl.jpg)

View File

@@ -0,0 +1,19 @@
# 队列
![image-20200624153725089](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3f3y8f35j30vf0dgwiw.jpg)
## 队列的定义
![image-20200624153857510](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3f5jwt16j30v90ejdn3.jpg)
![image-20200624154000138](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3f6n5z4yj30u60flh2o.jpg)
![image-20200624154121849](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3f82a7xdj30qi0fuq9i.jpg)
## 队列的基本操作
![image-20200624154224115](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3f9523mrj30y00euth1.jpg)
## 总结
![image-20200624154248823](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3f9k2lh7j30uu0dr79a.jpg)

View File

@@ -0,0 +1,53 @@
# 顺序队列
![image-20200624154351327](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fanepcfj30ve0dt0vz.jpg)
## 顺序队列的定义
![image-20200624154511213](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fc1hnm0j30y90gktky.jpg)
### 顺序队列的初始化
![image-20200624154606843](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fczuatuj30wu0gzwo7.jpg)
### 入队操作
![image-20200624155112673](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fibcpw0j30ri0f10wh.jpg)
![image-20200624155125271](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fiimg3vj30rf0f8dkr.jpg)
### 循环队列
![image-20200624155155915](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fj238xpj30qs0fdtcd.jpg)
![image-20200624155216098](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fjerveoj30qx0f0785.jpg)
### 出队
![image-20200624155258305](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fk4u3n1j30rk0fpn1s.jpg)
### 判空/判满
方案一:牺牲一个存储空间
![image-20200624155343663](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fkxhd4ij30qz0ftjv5.jpg)
方案二利用size变量记录队列长度
![image-20200624155414159](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3flg4hgej30qc0euado.jpg)
方案三利用tag记录最后一次操作
![image-20200624155619066](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fnmgc3dj30qy0f2dkj.jpg)
## 其它实现方式
![image-20200624155808035](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fpi4g82j30pw0djq6j.jpg)
![image-20200624155827353](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fpu5honj30nu0cs76e.jpg)
![image-20200624155906039](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fqii7nrj30nc0dpgnu.jpg)
## 总结
![image-20200624160059508](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fshe0aqj30x40hvwnq.jpg)

View File

@@ -0,0 +1,44 @@
# 链队列
![image-20200624160150945](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ftdkrv2j30v30ds42h.jpg)
## 链队列的定义
![image-20200624160334221](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fv5uhv6j30sc0grgs5.jpg)
## 链队列的基本操作
### 链队列的初始化
![image-20200624160434942](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fw7qcfij30xq0j0wpo.jpg)
### 入队
带头节点
![image-20200624160602691](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fxqiigij30yu0ffq7q.jpg)
不带头节点
![image-20200624160710140](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3fywji55j30wq0dwn6f.jpg)
### 出队
带有头节点
![image-20200624160905141](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3g0wnhuuj30x50gz465.jpg)
不带头节点
![image-20200624160952329](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3g1prhxgj30w80h1ti9.jpg)
### 判满
![image-20200624161057518](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3g2ugm1lj31050h6jyc.jpg)
## 总结
![image-20200624161134905](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3g3hwkxbj30x70hl7ba.jpg)

View File

@@ -0,0 +1,34 @@
# 双端队列
![image-20200624161331529](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3g5ijsqaj30og0gt0xt.jpg)
## 双端队列的定义
![image-20200624161416772](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3g6b1zgmj30px0h2gvk.jpg)
## 考点:判断输出序列的合法性
### 对于栈的输出序列的合法性
![image-20200624161642449](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3g8tspcwj30wn0fb441.jpg)
绿色为合法,红色为非法
### 对于输入受限的双端队列的输出序列的合法性
![image-20200624162025565](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3gcpf6fcj30wk0evq9k.jpg)
绿色为合法,红色为非法,带下划线是在栈中不合法,但在输入受限的双端队列中合法的。
### 对于输出受限的双端队列
![image-20200624162509184](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ghmbilrj30w20et454.jpg)
绿色为合法,红色为非法,带下划线是在栈中不合法,但在输出受限的双端队列中合法
这种输出受限的双端队列,看序号较大的元素输出的位置,这意味着,在它输出之前,比它小的元素的相对位置是确定的,接下来就是考虑有什么插入的方法能实现这种相对位置关系!
## 总结
## ![image-20200624162951819](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3gmivt6mj30xv09ddla.jpg)

View File

@@ -0,0 +1,148 @@
# 栈的应用
## 括号匹配问题
![image-20200624163218954](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3gp2nlldj30rl0epwl9.jpg)
### 实际过程
![image-20200624163415891](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3gr3qzzpj30vp08s41n.jpg)
####正好匹配
![image-20200624163523560](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3gs9w2tjj30lg0g640j.jpg)
####左右不匹配
![image-20200624163548297](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3gsp5eixj30ox0fftbx.jpg)
#### 右括号单身
![image-20200624163638571](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3gtkif5hj30uc0g1gp6.jpg)
#### 左括号单身
![image-20200624163721992](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3gubowzlj30v90f2whs.jpg)
#### 整个流程
![image-20200624163928215](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3gwicyinj30vc0k3aij.jpg)
### 算法实现
![image-20200624164327998](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3h0o6j1pj31010hudsw.jpg)
### 总结
![image-20200624164420239](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3h1knszrj30v00as42w.jpg)
## 表达式求值
![image-20200624164751528](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3h58yijoj30vj0dg0xs.jpg)
### 算数表达式是什么?
由三个部分组成(操作数,运算符,界限符)
![image-20200624165021200](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3h7ua9jbj30wk0g0dm6.jpg)
### 前/后缀表达式的诞生
![image-20200624165107095](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3h8muhumj30mp0gegrp.jpg)
### 中/后/前缀表达式的区别
![image-20200624165500339](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3hcoc0paj30tm0f2jy3.jpg)
#### 中转后的过程:
![image-20200624165755963](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3hfpzb8mj30vv0edjxe.jpg)
**上图中,后缀表达式的算术符的先后次序对应中缀表达式的生效的先后次序**,但是这是一定的吗?
![image-20200624170300224](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3hl04ewvj30yl0gtqfl.jpg)
左优先原则,可保证运算顺序唯一性,以确定机算算法输出结果的唯一性!!
![image-20200624190745666](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3l6tdpuuj30v50gnjxj.jpg)
#### 机算算法实现
![image-20200624191112704](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3laei7pbj30wf0gy10c.jpg)
![image-20200624191355054](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ld7kfcfj30pk0f4tcy.jpg)
### 中转前的过程
![image-20200624191538706](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3lf0me2pj30nt0egjv1.jpg)
中转后和中转前的区别:
![image-20200624191614443](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3lfmqs26j30ov0en0v6.jpg)
#### 中转前的机算过程:
![image-20200624191810971](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3lhnpy97j30xl0gejzu.jpg)
### 总结
![image-20200624191919379](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3liufbq4j30rg0fy0yf.jpg)
"左优先"/“右优先”原则和左/右操作数不是专业说法,仅供理解!
## 表达式求值——具体代码实现
![image-20200624192258712](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3lmn5bcuj30y407077j.jpg)
### 中转后机算
手算过程:
![image-20200624192506786](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3lov1ve7j30xi0h5n4t.jpg)
机算过程:
![image-20200624193355396](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3ly15bjcj30x20imakj.jpg)
### 中缀表达式的计算
![image-20200624193844266](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3m31iy57j30oh08cjuk.jpg)
![image-20200624194515343](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3m9tycovj30oi0eqjvv.jpg)
CPU只能执行单个的加减乘除运算上边这么搞的意义就是为了将高级程序语言编译成简单的机器码让CPU去执行
### 总结
![image-20200624194707110](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mbr9sqtj30p80dwjyq.jpg)
## 栈在递归中的应用
递归的过程就是函数调用的过程
![image-20200624195132597](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mgdjqtjj30xg0g77e5.jpg)
![image-20200624195412187](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mj4njfsj30q50d4whs.jpg)
### 适合用“递归”算法解决的问题
![image-20200624195452395](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mjtwxqnj30ny0ao40z.jpg)
求阶乘:
![image-20200624195709306](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mm7rbj5j30r50dw79a.jpg)
**使用递归时,需要注意调用栈溢出!**
![image-20200624200031925](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mppmy5uj30py0cxn0f.jpg)
**可以自定义栈将递归算法改造成非递归算法!**
求斐波那契数列
![image-20200624200155981](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mr6it0gj30pd0cwtbu.jpg)
### 总结
![image-20200624200214150](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mrhq6wnj30mq0adtbj.jpg)

View File

@@ -0,0 +1,26 @@
# 队列的应用
## 树的层次遍历
提示:不知道树这种数据结构的同学,可以考虑先跳过本文内容,等了解树之后,再来康康~
![image-20200624200711109](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mwnobv8j30y20fwjxo.jpg)
详细实现内容在树的章节实现!
## 图的广度优先遍历
遍历是指找出所有元素节点
![image-20200624200822823](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mxvo8h6j30x40dmn1j.jpg)
## 队列在操作系统中的应用
**CPU资源分配问题**
![image-20200624200936738](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3mz62g39j30wz0exn4l.jpg)
**打印数据缓冲区**
![image-20200624201203709](https://tva1.sinaimg.cn/large/007S8ZIlly1gg3n1pslqoj30mn0cuq69.jpg)

View File

@@ -0,0 +1,14 @@
# 栈和队列
## 笔记目录
* [](Doc_2_0_栈.md)
* [顺序栈](Doc_2_1_顺序栈.md)
* [链栈](Doc_2_2_链栈.md)
* [队列](Doc_2_3_队列.md)
* [顺序队列](Doc_2_4_顺序队列.md)
* [链式队列](Doc_2_5_链式队列.md)
* [双端队列](Doc_2_6_双端队列.md)
* [栈的应用](Doc_2_7_栈的应用.md)
* [队列的应用](Doc_2_8_队列的应用.md)