【数据结构】 栈的应用-括号匹配
实验要求:
括号匹配检验:假设表达式中允许包括两种括号:圆括号和方括号,其嵌套的顺序随意,即()或[([][])]等为正确的格式,[(])或([())等均为不正确格式。输入一个表达式,判断其中的括号是否能正确匹配。
代码实现:
1,头文件
#define MAX 100 //栈的最大值
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STACKSIZE 100
#define STACKNUMBER 10
#define OK 0
#define ERROR 1
#define OVERFLOW -2
typedef int Status;
typedef char SElemType; //元素类型
2.结构体
typedef struct
{
SElemType *base;
SElemType *top;
int stacksize;
} SqStack;
3.菜单
Status InitStack(SqStack &S);//构建一个空栈s
Status Pop(SqStack &S);//删除栈顶元素
Status Push(SqStack &S,SElemType e);//插入元素
Status Check(SqStack &S,SElemType e);//判断
4.函数实现
//构建一个空栈
Status InitStack(SqStack &S)
{
S.base=(S