主题:斑竹帮帮我 个路高手看看晚上写的程序
晚上写的一个题目 改了一段时间 没找出错误 大家看看
#define ERROR 0
#define OK 1
#define TURE 1
#define FALSE 0
#define OVERFLOW -1
#define NULL 0
#define INIT_STACK_SIZE 10
#define STACKINCREMENT 10
typedef int SElemType ;
typedef int status ;
typedef struct { /*定义一个栈*/
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
status InitStack(SqStack *S) /*初始化一个栈*/
{
S->base=(SElemType*)malloc(INIT_STACK_SIZE*sizeof(SElemType));
if(S->base==NULL)
{
printf("out of space");
exit(OVERFLOW);
}
S->base=S->top;
S->stacksize=INIT_STACK_SIZE;
return OK;
}
status PushStack(SqStack *S,SElemType *e) /*进栈操作*/
{
if(S->base-S->top>=S->stacksize)
{
S->base=(SElemType*)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(SElemType));
if(S->base==NULL)
{
printf("out of space");
exit(OVERFLOW);
}
S->top=S->base+S->stacksize;
S->stacksize+=STACKINCREMENT;
}
*S->top++=e;
return OK;
}
status PopStack(SqStack *S,SElemType *e) /*出栈操作*/
{
if(S->base==S->top)
return ERROR;
*e=*--S->top;
return OK;
}
/*判断栈是否为空*/
status EmptyStack(*S)
{
if(S->base==S->top)
return TURE;
return FALSE;
}
status DestroyStack(*S) /*销毁一个栈*/
{
S->base=S->top;
return OK;
}
main() /*主函数*/
{
int i,M;
SqStack S;
char e;
M=TURE;
char str[];
printf("请输入要测试的表达式"); /*输入初始值*/
scanf("%s",str);
for(i=0;i<strlen(str)&&M;i++)
{ switch(str[i])
{ case '(':
case '{':
case '[':
PushStack(&S,str[i])
break;
case'}':
if(EmptyStack(&S))
{
printf("NOT March");
M=FALSH;
break;
}
PopStack(&S,&e);
if(e=='}')
break;
case']':
if(EmptyStack(&S))
{
printf("NOT March");
M=FALSH;
break;
}
PopStack(&S,&e);
if(e==']')
break;
case')':
if(EmptyStack(&S))
{
printf("NOT March");
M=FALSH;
break;
}
PopStack(&S,&e);
if(e==')')
break;
}
}
if(EmptyStack(&S))
{ printf(" Match \n");
printf("Not Match\n");
DestroyStack(&S)
system("pause");
return 0;
}
}
#define ERROR 0
#define OK 1
#define TURE 1
#define FALSE 0
#define OVERFLOW -1
#define NULL 0
#define INIT_STACK_SIZE 10
#define STACKINCREMENT 10
typedef int SElemType ;
typedef int status ;
typedef struct { /*定义一个栈*/
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
status InitStack(SqStack *S) /*初始化一个栈*/
{
S->base=(SElemType*)malloc(INIT_STACK_SIZE*sizeof(SElemType));
if(S->base==NULL)
{
printf("out of space");
exit(OVERFLOW);
}
S->base=S->top;
S->stacksize=INIT_STACK_SIZE;
return OK;
}
status PushStack(SqStack *S,SElemType *e) /*进栈操作*/
{
if(S->base-S->top>=S->stacksize)
{
S->base=(SElemType*)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(SElemType));
if(S->base==NULL)
{
printf("out of space");
exit(OVERFLOW);
}
S->top=S->base+S->stacksize;
S->stacksize+=STACKINCREMENT;
}
*S->top++=e;
return OK;
}
status PopStack(SqStack *S,SElemType *e) /*出栈操作*/
{
if(S->base==S->top)
return ERROR;
*e=*--S->top;
return OK;
}
/*判断栈是否为空*/
status EmptyStack(*S)
{
if(S->base==S->top)
return TURE;
return FALSE;
}
status DestroyStack(*S) /*销毁一个栈*/
{
S->base=S->top;
return OK;
}
main() /*主函数*/
{
int i,M;
SqStack S;
char e;
M=TURE;
char str[];
printf("请输入要测试的表达式"); /*输入初始值*/
scanf("%s",str);
for(i=0;i<strlen(str)&&M;i++)
{ switch(str[i])
{ case '(':
case '{':
case '[':
PushStack(&S,str[i])
break;
case'}':
if(EmptyStack(&S))
{
printf("NOT March");
M=FALSH;
break;
}
PopStack(&S,&e);
if(e=='}')
break;
case']':
if(EmptyStack(&S))
{
printf("NOT March");
M=FALSH;
break;
}
PopStack(&S,&e);
if(e==']')
break;
case')':
if(EmptyStack(&S))
{
printf("NOT March");
M=FALSH;
break;
}
PopStack(&S,&e);
if(e==')')
break;
}
}
if(EmptyStack(&S))
{ printf(" Match \n");
printf("Not Match\n");
DestroyStack(&S)
system("pause");
return 0;
}
}