#include<stdio.h>
#define MAXSIZE 100
typedef struct
{
char ST[MAXSIZE] ;
int top;
}stack;
stack A;
int m;
//比较匹配
compare(char ch[m],int tag)
{
int m,i,j;
tag=1;
printf("请输入你要判断的式子个数m/n");
scanf("%d",&m);
printf("请输入你要 判别的表达式/n");
for(i=0;i<m;i++)
scanf("%s",&ch[i]);
j=m-i;
while(j<=m&&tag)
{
if (ch[j]=='('||ch[j]=='['||ch[j]=='{')
{ A.top++;
A->ST[A.top]=ch[i];
}
if(ch[j]==')')
if(A->ST[A.top]=='(') A.top--;
else tag =0;
if(ch[j]==']')
if(A->ST[A.top]=='[') A.top--;
else tag =0;
if(ch[j]=='}')
if(A->ST[A.top]=='{') A.top--;
else tag =0;
j++;}
if(A.top>0) tag=0;
return tag;
}
void main()
{
int tag;
compare(char ch(m),int tag);
printf("%d",tag);
}
数据结构实验--括号匹配算法改进
最新推荐文章于 2024-09-20 14:26:28 发布