求指点,用栈解决·符号前后两个字符串是否对称相等问题
程序代码:#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define STACK_INIT_SEZE 100
#define STACKINCREMENT 10
#define OVERFLOW -1
#define OK 0;
#define ERROR -2;
typedef int SElemType;
typedef struct {
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
int Initstack(SqStack *s){
s->base=(SElemType*)malloc(STACK_INIT_SEZE*sizeof(SElemType));
if(!s->base) return OVERFLOW;
s->top=s->base;
s->stacksize=STACK_INIT_SEZE;
return OK;
}//initstack
int Push (SqStack *s,SElemType e){
if(s->top-s->base>=s->stacksize){
s->base=(SElemType*)realloc(s->base,(s->stacksize+STACK_INIT_SEZE)*sizeof(SElemType));
if(!s->base) return OVERFLOW;
s->top=s->base+s->stacksize;
s->stacksize+=STACKINCREMENT;
}
*s->top=e;
return OK;
}//push
int Pop(SqStack *s,SElemType e){
if(s->top==s->base) return ERROR;
e=*--s->top;
return OK;
}//POP
int DestroyStack(SqStack *s){
SElemType *p;
for(p=s->top;s->top!=s->base;p=s->top){
--s->top;
free(p);
}
if(s->top==s->base)
return 0;
}
int main(){
int i=0;
char x,a[STACK_INIT_SEZE];
SqStack *s;
Initstack(s);
printf("Please input the srings:\n");
gets a;
while(a[i]!=&){
Push(s,a[i]);
i++;
}
if(!a[i]) printf("The elements before and after @ do not equal! ");
i++;
while(a[i]){
Pop(s,x);
if(x!=a[i]){
DestroyStack(s);
printf("The elements before and after @ do not equal! ");
}
i++;
}
printf("The elements before and after @ equal! ");
}









