数据结构之利用栈判断字符串是否对称

#include<stdio.h>
#include<stdlib.h>
#define MaxSize 100
typedef struct
{
	char data[MaxSize];
	int top;
}SqStack;
void InitStack(SqStack *&s)//begin Stack
{
	s=(SqStack *)malloc(sizeof(SqStack));
	s->top=-1;
}
void DestroyStack(SqStack * &s)//free Stack
{
	free(s);
}


bool StackEmpty(SqStack *s)//Empty???
{
	return(s->top==-1);
}


bool Push(SqStack *&s,char e)    //push one by one 
{
	if(s->top==MaxSize-1)
	{
		return false;
	}
	s->top++;
	s->data[s->top]=e;
	return true;
}
bool Pop (SqStack *&s,char &e)//pop one by one
{
	if(s->top==1)
	{
		return false;
	}
	e=s->data[s->top];
	s->top--;
	return true;
}
bool symmetry(char str[])
{
	int i;char e;
	SqStack *st;
	InitStack(st);
	for(i=0;str[i]!='';i++)
	{
		Push(st,str[i]);
	}
	for(i=0;str[i]!='';i++)
	{
		Pop(st,e);
		if(str[i]!=e)
		{
			DestroyStack(st);
		    printf("Not 0||0");
		}
	}
	DestroyStack(st);
	printf("0||0");
}

int main()
{   char str[MaxSize];
    for(int i=0;i<MaxSize;i++)
    {
       	scanf("%c",str[i]);
    	if(str[i]=='')
    	{
    		break;
		}
	}
	symmetry(str);
 } 

存在小问题,欢迎指出

原文地址:https://www.cnblogs.com/AmosAlbert/p/12832367.html