int Index_KMP(SString S, SString T, int pos, int next[])
{ // 利用模式串T的next函数求T在主串S中第pos个字符之后的位置的KMP算法。
// 其中,T非空,1≤pos≤StrLength(S)。算法4.6
int i = pos, j = 1;
while (i <= S[0] && j <= T[0])
if (j == 0 || S[i] == T[j]) // 继续比较后继字符
{
++i;
++j;
}
else // 模式串向右移动
j = next[j];
if (j > T[0]) // 匹配成功
return i - T[0];
else
return 0;
}