当前位置:网站首页>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
边栏推荐
- BIM and safety in road maintenance-buildSmart Spain
- Joint Time-Frequency and Time Domain Learning for Speech Enhancement
- 迅为i.MX8Mmini开发板离线构建Yocto系统
- Virtualenv+pipenv virtual environment management
- 本科毕业四年:工作,辞职,结婚,买房
- STM32 project practice (1) introduction and use of photosensitive resistor
- Efforts at the turn of the decade
- MySQL的零拷贝技术
- ASTM D 3801 vertical burning test of solid plastics
- Wechat applet reports an error: [rendering layer network layer error] pages/main/main Local resource pictures in wxss cannot be obtained through wxss. You can use network pictures, Base64, or < image/
猜你喜欢

What are the PHP FPM configuration parameters

Uniapp uses uni upgrade Center

Onenet Internet of things platform - mqtt product devices send messages to message queues MQ
![[classic example] classic list questions @ list](/img/d8/a259e5f9d08eacbef31254d1bc3304.jpg)
[classic example] classic list questions @ list
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 5](/img/f5/9c68b3dc30362d3776c262fdc13fd0.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 5
![[datawhale202206] pytorch recommendation system: precision model deepfm & DIN](/img/4f/8799016731a2c1647b6f2f4d96b754.png)
[datawhale202206] pytorch recommendation system: precision model deepfm & DIN

Four years after graduation: work, resign, get married, buy a house

Use of easyexcel
![[MCU] [nixie tube] nixie tube display](/img/5e/9e14302b4e4f5e03601392ac90479d.png)
[MCU] [nixie tube] nixie tube display

Onenet Internet of things platform - mqtts product equipment connected to the platform
随机推荐
USB peripheral driver - cable connect/disconnect
Onenet Internet of things platform - mqtt product equipment upload data points
Machine learning - Data Science Library - day two
【20220605】文献翻译——虚拟现实中的可视化:一个系统的回顾
The operation process of using sugar to make a large data visualization screen
ANSI/UL 94 VTM薄质材料垂直燃烧测试
Typora adds watermarks to automatically uploaded pictures
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
CPI tutorial - asynchronous interface creation and use
Four years after graduation: work, resign, get married, buy a house
6.30模拟赛总结
Sum of factor numbers of interval product -- prefix sum idea + fixed one shift two
leetcode 406. Queue reconstruction by height
区间乘积的因子数之和——前缀和思想+定一移二
C # dependency injection (straight to the point) will be explained as soon as you see the series
【datawhale202206】pyTorch推荐系统:多任务学习 ESMM&MMOE
C summary of knowledge points 1
指定的服务已标记为删除
[20211129] configuration du serveur distant du carnet de notes jupyter
Seckill system 03 - redis cache and distributed lock

