当前位置:网站首页>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
边栏推荐
- Dlhsoft Kanban, Kanban component of WPF
- Relationship between accuracy factor (DOP) and covariance in GPS data (reference link)
- Rural guys earn from more than 2000 a month to hundreds of thousands a year. Most brick movers can walk my way ǃ
- NOV Schedule for . Net to display and organize appointments and recurring events
- C#依赖注入(直白明了)讲解 一看就会系列
- 关于NAND FLASH解扣的认识
- Joint Time-Frequency and Time Domain Learning for Speech Enhancement
- One year anniversary of bitbear live studio, hero rally order! I invite you to take a group photo!
- Ansible的playbook
- Onenet Internet of things platform - mqtt product equipment upload data points
猜你喜欢

迅为i.MX8Mmini开发板离线构建Yocto系统

2022-06-28-06-29

Chapter 14 signals (IV) - examples of multi process tasks

STM32 project practice (1) introduction and use of photosensitive resistor

【datawhale202206】pyTorch推荐系统:多任务学习 ESMM&MMOE

How to use opcache, an optimization acceleration component of PHP

Virtualenv+pipenv virtual environment management
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8](/img/16/e1a0a52964c8a55eb729469114fc60.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8

The Missing Semester

Common chart usage of Bi tools
随机推荐
Build yocto system offline for i.mx8mmini development board
Compile and debug net6 source code
本科毕业四年:工作,辞职,结婚,买房
Sleep quality today 79 points
Golang根据参数引入相应配置文件的实现方式
C summary of knowledge points 1
One year anniversary of bitbear live studio, hero rally order! I invite you to take a group photo!
How to use opcache, an optimization acceleration component of PHP
队列的链式存储
Blue Bridge Cup multi interface switching processing (enumeration plus state machine method)
Interpretation of R & D effectiveness measurement framework
[shell programming] - shell introductory learning
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8
[20211129] configuration du serveur distant du carnet de notes jupyter
【语音信号处理】3语音信号可视化——prosody
The operation process of using sugar to make a large data visualization screen
MySQL的零拷贝技术
Computer graduation project asp Net hotel room management system VS development SQLSERVER database web structure c programming computer web page source code project
Sort out relevant contents of ansible
ASTM D 3801 vertical burning test of solid plastics

