当前位置:网站首页>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
边栏推荐
- Self organization is the two-way rush of managers and members
- C summary of knowledge points 1
- Ipv6-6to4 experiment
- 迅为i.MX8Mmini开发板离线构建Yocto系统
- Typora realizes automatic uploading of picture pasting
- Sort out relevant contents of ansible
- C serialization simple experiment
- [20211129] jupyter notebook remote server configuration
- Eurake分区理解
- [datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE
猜你喜欢
Typora adds watermarks to automatically uploaded pictures
The Missing Semester
MySQL workbench data modeling function
Sort out relevant contents of ansible
[some notes]
队列操作---
Typora realizes automatic uploading of picture pasting
【20211129】Jupyter Notebook遠程服務器配置
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8
Switch basic experiment
随机推荐
The specified service is marked for deletion
The Missing Semester
Onenet Internet of things platform - mqtt product devices send messages to message queues MQ
easyexcel的使用
技术分享 | MySQL:从库复制半个事务会怎么样?
Technology sharing | MySQL: how about copying half a transaction from the database?
fatal error: execution: 没有那个文件或目录
Golang根据参数引入相应配置文件的实现方式
第十四章 信号(四)- 多进程任务示例
What are the PHP FPM configuration parameters
JPA and criteria API - select only specific columns - JPA & criteria API - select only specific columns
Joint Time-Frequency and Time Domain Learning for Speech Enhancement
JS reverse | m3u8 data decryption of a spring and autumn network
How to install php7 and perform performance test using yum
GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021
【20220605】文献翻译——虚拟现实中的可视化:一个系统的回顾
kubernetes之ingress探索实践
Understanding of NAND flash deblocking
Consolidate -c operator
Four years after graduation: work, resign, get married, buy a house