主题:关于串回文判读的问题
我用链栈编了一个回文串判读问题,编译通过了,就是运行时要报错,求高人赐教
#include<iostream>
using namespace std;
typedef struct Stack
{
char data;
struct Stack *next;
}Stactk,*Link;
void Creat(Link &S)
{
S=(Link)malloc(sizeof(Link));
S->next=NULL;
}
void Push(Link &S,char e)
{
Link p;
p=(Link)malloc(sizeof(Link));
p->data=e;
p->next=S;
S=p;
}
void Pop(Link &S,char e)
{
Link p;
if(p==NULL)
cout<<"The stack is empty"<<endl;
else
{
e=S->data;
p=S;
S=S->next;
free(p);
}
}
void main()
{
char s1[20],s2[20];
Link S;
int i=0,j=0;
Creat(S);
cout<<"Please input a string "<<endl;
cin>>s1;
for(;i<strlen(s1);i++)
{
if(s1[i]!=' ')
Push(S,s1[i]);
}
for(;j<strlen(s1);j++)
Pop(S,s2[j]);
if(strcmp(s1,s2)==0)
cout<<"This Word is Huiwen"<<endl;
else
cout<<"This Word is not Huiwen"<<endl;
}
#include<iostream>
using namespace std;
typedef struct Stack
{
char data;
struct Stack *next;
}Stactk,*Link;
void Creat(Link &S)
{
S=(Link)malloc(sizeof(Link));
S->next=NULL;
}
void Push(Link &S,char e)
{
Link p;
p=(Link)malloc(sizeof(Link));
p->data=e;
p->next=S;
S=p;
}
void Pop(Link &S,char e)
{
Link p;
if(p==NULL)
cout<<"The stack is empty"<<endl;
else
{
e=S->data;
p=S;
S=S->next;
free(p);
}
}
void main()
{
char s1[20],s2[20];
Link S;
int i=0,j=0;
Creat(S);
cout<<"Please input a string "<<endl;
cin>>s1;
for(;i<strlen(s1);i++)
{
if(s1[i]!=' ')
Push(S,s1[i]);
}
for(;j<strlen(s1);j++)
Pop(S,s2[j]);
if(strcmp(s1,s2)==0)
cout<<"This Word is Huiwen"<<endl;
else
cout<<"This Word is not Huiwen"<<endl;
}