0001 void buildNext(char* P, int m, int* next) { //构造模式串P的next表 0002 for (int t = next[0] = -1, j = 0; j < m-1; ) //从首项为-1起,递推地逐项计算 0003 if (0 > t || P[t] == P[j]) //匹配 0004 next[++j] = ++t; //则递增赋值(此处稍后会改进) 0005 else //否则 0006 t = next[t]; //继续尝试下一值得尝试的位置 0007 } //buildNext