各位高手帮忙看看啦。
我是用栈判断回文字符串
#include <iostream>
using namespace std;
#include <malloc.h>
typedef struct stonde
{
char data;
struct stonde *next;
}Stacknode;
int ishw(char str[])
{
int i=0;char ch;
Stacknode *st=NULL,*p;
while((ch=str[i++])!='\0') //进栈
{
p=(Stacknode *)malloc(sizeof(Stacknode));
p->data=ch;
p->next=st;
st=p;
}
i=0;
while(st!=NULL)
{
p=st;
ch=p->data; //出栈
st=st->next;
free(p);
if(ch!=str[i++])
return 0;
}
return 1;
}
int main()
{
char str[]="abcdcba";
int ishw(char str[]);
}