#include<stdio.h>
#include<malloc.h>
#define MaxSize 100
typedef char ElemType;
typedef struct
{
ElemType data[MaxSize];
int top;
} SqStack;
void InitStack(SqStack *&s){
s = (SqStack *)malloc(sizeof(SqStack));
s->top = -1;
}
bool Push(SqStack *&s, ElemType e){
if(s->top = MaxSize - 1)
return false;
s->top++;
s->data[s->top] = e;
return true;
}
bool Pop(SqStack *&s, ElemType &e) {
if (s->top == -1)
return false;
e = s->data[s->top];
s->top--;
return true;
}
void DestroyStack(SqStack *&s){
free(s);
}
bool symmetry(ElemType str[])
{ int i;
ElemType e;
SqStack *st;
InitStack(st);
for (i = 0; str[i] != '\0'; i++)
Push(st,str[i]);
for (i = 0; str[i] != '\0'; i++)
{ Pop(st, e);
if(e != str[i] )
{ DestroyStack(st);
return false;
}
}
DestroyStack(st);
return true;
}
int main()
{
ElemType str[]="abcba";
if(symmetry(str))
{
printf("%s是对称字符串",str);
}
else
{
printf("%s不是对称字符串",str);
}
return 1;
}