#2
crystall2012-12-18 11:05
回复 楼主 James429
|
int *findNext(String P) // 计算向量N
{
int m = P.length(); // m为模板P的长度
assert( m > 0); // 若m=0,退出
int *next = new int[m]; // 动态存储区开辟整数数组
assert( next != 0); // 若开辟存储区域失败,退出
next[0] = -1;
int i = 0;
int k = -1;
while (i < m-1)
{
while (k>= 0 && P [i] != P[k])
k= next[k];
i++; k++;
next[i] = k;
}
return next;
}
字符串是abcabcad,程序还少那些东西?