KMP(next)算法c语言实现
/****************************************************************************** *文件名:实验3.c
*文件描述:试编写一程序,实现KMP算法,输入三组主串S和模式串P,输出模式串的 *Next(j)函数值,
*以及该P在S中的位置的定位函数值,即序号值。其中S的长度为15~25,P的长度为5~8。 *创建人:赵军伟 2009.11.15
******************************************************************************/ #include
#include
struct node
{
char data;
struct node *next;
};
struct node* input()
{
struct node *str;
struct node *p,*r;
char x;
int n=0;
/*str=NULL;*/
scanf("%c",&x);
while(x!='\n')
{
n=n+1;
p=(struct node*)malloc(sizeof (struct node));
p->data=x;
p->next=NULL;
if(n==1)
{
str=p;
}
else
{
r->next=p;
}
r=p;
scanf("%c",&x);
}
return str;
}
void Output(struct node * str)
{
struct node*p;