BF的C实现
int Index(SString S,SString T,int pos)
/* 其中,T非空,1≤pos≤StrLength(S)。算法4.5 */
int i,j;
if(1<=pos&&pos<=S[0])
{
i=pos;
j=1;
while(i<=S[0]&&j<=T[0])/*S[0],T[0]中存放的为串长*/
if(S[i]==T[j]) /* 继续比较后继字符 */
{
++i;
++j;
}
else /* 指针后退重新开始匹配 */
{
i=i-j+2;
j=1;
}
if(j>T[0])
return i-T[0];
else
return 0;
}
else
return 0;
}
KMP的详解
http://blog.csdn.net/yaochunnian/article/details/7059486