当前位置:网站首页>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
边栏推荐
- IOS interview
- Golang introduces the implementation method of the corresponding configuration file according to the parameters
- CPI教程-异步接口创建及使用
- Unity XLua 协程封装
- 第十四章 信号(四)- 多进程任务示例
- Use of easyexcel
- 指定的服务已标记为删除
- 区间乘积的因子数之和——前缀和思想+定一移二
- Onenet Internet of things platform - the console sends commands to mqtt product devices
- JS reverse | m3u8 data decryption of a spring and autumn network
猜你喜欢
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7](/img/41/e3ecbd49e4bfeab6c6e7d8733fe33a.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7
![[JS] interview questions](/img/f3/8cf430b999980190a250f89537715e.jpg)
[JS] interview questions

Summary of JFrame knowledge points 1

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

IOS interview

Virtualenv+pipenv virtual environment management

uniapp 使用 uni-upgrade-center

Onenet Internet of things platform - mqtts product equipment connected to the platform

循环链表--

LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
随机推荐
2022-06-28-06-29
Virtualenv+pipenv virtual environment management
Pandas reads MySQL data
C # dependency injection (straight to the point) will be explained as soon as you see the series
自组织是管理者和成员的双向奔赴
ASP. Net core 6 from entry to enterprise level practical development application technology summary
(混更一篇)多个txt文本转一个表格
Mysql database knowledge collation
C summary of knowledge points 1
队列操作---
Chapter 14 signals (IV) - examples of multi process tasks
NOV Schedule for . Net to display and organize appointments and recurring events
顺序表有关操作
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8
关于NAND FLASH解扣的认识
Golang des-cbc
Ipv6-6to4 experiment
【20211129】Jupyter Notebook遠程服務器配置
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
本科毕业四年:工作,辞职,结婚,买房

