KMP的问题会有人帮我么

来源:百度知道 编辑:UC知道 时间:2024/06/09 02:22:42
#include<stdio.h>
#include<stdlib.h>
#define NULL 0
typedef struct
{
char *ch;
int length;
}hstring;
int next[50];
main()
{
void initstring(hstring *s);
void strassign(hstring *s,char *ch);
int index_kmp(hstring *t,hstring *s,int pos);
int pos;
hstring s,t;
initstring(&s);
initstring(&t);
strassign(&t,"acabaabcaabaabcac");
strassign(&s,"abaabcac");
pos=1;
printf("%d",index_kmp(&t,&s,pos));
}
void initstring(hstring *s)/*初始化*/
{
s->ch=NULL;
s->length=0;
}
void strassign(hstring *s,char *ch)/*输入*/
{
int i,j;
char *c;
if(s->ch)
free(s->ch);
c=ch;
i=0;
while(*c)
{c++;i++;}
if(!i)
{
s->length=0;
s->ch=NULL;
}
else
{
if(!(s->ch=(char *)malloc(i*sizeof(char)+1)))
exit

这个问题我没办法直接回答你,因为你还是没理解KMP算法
int index_kmp(hstring *t,hstring *s,int pos)
这个函数有严重错误,我刚才回答了你的KMP算法的那个问题,看样子你还是没明白我说的,你先去理解一下我说的那几句话,问题的根源就在那,你理解了这也就解决了,理解不了我这说一万句也是废话,望楼主好好理解