数据结构实验--括号匹配算法改进

#include
#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  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);
}

你可能感兴趣的:(数据结构实验,数据结构,算法,struct)