当前位置:网站首页>Stack-------
Stack-------
2022-07-01 12:23:00 【Between the steps】
Order of the stack , use Sequential storage Implementation stack , Its basic operation : Additions and deletions , Sentenced to empty , Full sentence operation
1. The first is initialization :
#include<stdio.h>
#define Maxsize 10 // The maximum number of elements in the stack
typedef struct{
ElemType data[Maxsize]; // Stack elements in static arrays
int top; // Top pointer of stack
}SqStack;
void InitStack(SqStack &S){
S.top=-1; // Initialize the stack top pointer
}
bool StackEmpty(SqStack S){
if(S.top==-1)
return true; // The stack is empty
else
return false;
}
void testStack{
SqStack S; // Declare a sequential stack , Allocate space for it
}
int main(){
SqStack S;
InitStack(S);
// Subsequent addition, deletion, modification and query
}

2. Stack in operation
First judge whether the stack is full , If you are dissatisfied, let the pointer at the top of the stack add 1, Then put new elements on the stack
bool push(SqStack &S,ElemType x){
if(S.top==Maxsize-1) // Stack full , Report errors
return false;
S.top=S.top+1; // The pointer first adds 1
S.data[S.top]=x; // Put new elements on the stack
return true;
}

3. The stack,
bool Pop(SqStack &S,ElemType &x){
if(S.top==-1)
return false; // The stack is empty ,, Report errors
x=S.data[S.top]; // The top element of the stack goes out of the stack first
S.top=S.top-1; // Pointer minus 1
return true;
}

4. Read the top element of the stack
bool GetTop(SqStack S,ElemType &x){
if(S.top==-1)
return false;
x=S.data[S.top];
return true;
}

Shared stack
Shared stack
The shared stack has pointers at the bottom and top of the stack
#include<stdio.h>
#define Maxsize 10 // The maximum number of elements in the stack
typedef struct{
ElemType data[Maxsize]; // Stack elements in static arrays
int top0; //0 No. stack top pointer
int top1; //1 No. stack top pointer
}SqStack;
void InitStack(SqStack &S){
S.top0=-1; // initialization top0 Top pointer of stack
S.top1=Maxsize; // initialization top1 Top pointer of stack
}

Conditions for stack full :top0+1==top1 ?
Chain stack
Chain stack
The chain stack is similar to the header insertion of a single chain table , The one inserted after is on the right Such as
So we just need to stack at the head of the chain
typedef struct{
ElemType data;
struct LinkNode *next;
}LinkNode,*LiStack;
Like a single chain watch
边栏推荐
- C#依赖注入(直白明了)讲解 一看就会系列
- IOS interview
- Fatal error: execution: there is no such file or directory
- 91.(cesium篇)cesium火箭發射模擬
- C knowledge point form summary 2
- Chapter 14 signals (IV) - examples of multi process tasks
- Ipv6-6to4 experiment
- Ansible的playbook
- Computer graduation project asp Net attendance management system vs developing SQLSERVER database web structure c programming computer web page source code project
- Eurake分区理解
猜你喜欢

Onenet Internet of things platform - mqtt product devices send messages to message queues MQ
![[Yunju entrepreneurial foundation notes] Chapter VII Entrepreneurial Resource test 1](/img/be/1194125442aaa2d7cc20b6a4a6762a.jpg)
[Yunju entrepreneurial foundation notes] Chapter VII Entrepreneurial Resource test 1
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3](/img/ea/c5e8d12007873385fa0d197fa62fd2.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3

【20211129】Jupyter Notebook远程服务器配置

Uniapp uses uni upgrade Center

比特熊直播间一周年,英雄集结令!邀你来合影!
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4](/img/4f/bc6c39ef4f2d1c4bdad8420f7badac.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4
![[20211129] jupyter notebook remote server configuration](/img/7c/79c9fcb91bde75e954dc3ecf9f5afd.png)
[20211129] jupyter notebook remote server configuration

GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021

【20211129】Jupyter Notebook遠程服務器配置
随机推荐
6.30模拟赛总结
Ansible的playbook
C#依赖注入(直白明了)讲解 一看就会系列
Interpretation of R & D effectiveness measurement framework
CPI教程-异步接口创建及使用
91. (cesium chapter) cesium rocket launch simulation
Consolidate -c operator
Indefinite integral
USB peripheral driver - cable connect/disconnect
LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
ASTM D 3801 vertical burning test of solid plastics
Sleep quality today 79 points
Onenet Internet of things platform - create mqtts products and devices
队列操作---
The Missing Semester
IOS interview
Unity XLua 协程封装
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4
巩固-C#运算符
leetcode 406. Queue Reconstruction by Height(按身高重建队列)

