求助程序哪里有问题?括号匹配问题
括号配对#include<stdio.h>
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
typedef char ElemType;
#define true 1
#define false 0
#define MaxSize 10
typedef struct
{
ElemType data[MaxSize];
int top;
}StType;
void InitStack(StType *&s)
{
s=(StType *)malloc(sizeof(StType));
s->top=-1;
}
void DestoryStack(StType *&s)
{
free(s);
}
bool StackEmpty(StType *&s)
{
return(s->top==-1);
}
bool Push(StType *&s,ElemType e)
{ if(s->top==MaxSize)
return 0;
s->top++;
s->data[s->top]=e;
return 1;
}
bool Pop(StType *&s,ElemType &e)
{ if(s->top==-1)
return 0;
e=s->data[s->top];
s->top--;
return true;
}
bool GetTop(StType *&s,ElemType &e)
{ if(s->top==-1)
return false;
e=s->data[s->top];
return true;
}
bool Match(char exp[],int n)
{
int i=0;char e;
bool match=true;
StType * st;
InitStack (st);
while(i<n&&match)
{ if(exp[i]=='(')
Push (st,exp[i]);
else if(exp[i]==')')
{ if(GetTop(st,e)==true)
{
if(e!='(')
match=false;
else
Pop(st,e);
}
else match=false;
}
i++;
}
if(!StackEmpty(st))
match=false;
DestoryStack(st);
return match;
}
int main()
{
char exp[20];
printf("请输入表达式:\n");
gets(exp);
if(Match(exp,strlen(exp)==1))
printf("表达式%s 括号配对\n",exp);
else
printf("表达式%s 括号不配对\n",exp);
return 0;
}