当前位置:网站首页>栈的应用——括号匹配问题
栈的应用——括号匹配问题
2022-07-01 12:05:00 【Between the steps】
栈的应用——括号匹配问题
#include<stdio.h>
#define MaxSize 10
typedef struct{
char data[MaxSize]; //静态数组存放栈中元素
int top; //栈顶指针
}SqStack;
//初始化栈
void InitStack(SqStack &S){
}
//判断栈是否为空
bool StackEmpty(SqStack s){
}
//新元素入栈
bool Push(SqStack &s,char x){
}
//栈顶元素出栈,用x返回
bool Pop(SqStack &s, char &x){
}
bool braketCheak(char str[],int length){
//字符放在str[]数组中,length 是其长度
SqStack S; //创建栈为其分配空间
InitStack(S);
for(int i=0;i<length;i++){
if(str[i]=='(' ||str[i]=='['||str[i]=='{'){
Push(S,str[i]); //左括号入栈
}else{
if(StackEmpty(S)) //如果不是左括号的话,该出栈了,如栈为空,则false
return false;
char topElem; //出栈的元素
Pop(S,topElem); //栈顶元素出栈
if(str[i]==')'&& topElem!='(')
return false;
if(str[i]==']'&& topElem!='[')
return false;
if(str[i]=='}'&& topElem!='{')
return false;
}
}
return StackEmpty(S); //都匹配完如果栈为空的话则返回true,否则返回false
}
int main(){
}
边栏推荐
- LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2
- Seckill system 03 - redis cache and distributed lock
- Comment Nike a - t - il dominé la première place toute l'année? Voici les derniers résultats financiers.
- Learning summary on June 29, 2022
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 8
- 241. 为运算表达式设计优先级 : DFS 运用题
- Is it safe for Huatai Securities to open an account online?
- Summary of JFrame knowledge points 1
- How to set decimal places in CAD
猜你喜欢

Onenet Internet of things platform - mqtts product equipment connected to the platform
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2](/img/2b/f42ac6745eb126254af62ad5217f70.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2

ACLY与代谢性疾病

Summary of JFrame knowledge points 1

Redis的攻击手法

Computer graduation project asp Net hotel room management system VS development SQLSERVER database web structure c programming computer web page source code project

C serialization simple experiment

Onenet Internet of things platform - the console sends commands to mqtt product devices

Consolidate -c operator

【20211129】Jupyter Notebook远程服务器配置
随机推荐
Le semester manquant
Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
Neo4j Chinese developer monthly - issue 202206
[MCU] [nixie tube] nixie tube display
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4
NOV Schedule for . Net to display and organize appointments and recurring events
S7-1500plc simulation
Onenet Internet of things platform - create mqtts products and devices
Sum of factor numbers of interval product -- prefix sum idea + fixed one shift two
对于mvvm和mvc的理解
Seckill system 03 - redis cache and distributed lock
About keil compiler, "file has been changed outside the editor, reload?" Solutions for
基于IMDB评论数据集的情感分析
Machine learning - Data Science Library Day 3 - Notes
Use set_ Handler filters out specific SystemC wrapping & error messages
Consolidate -c operator
LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
Kafuka learning path (I) Kafuka installation and simple use
自定義 grpc 插件
博途V15添加GSD文件