0001 int* buildNext ( char* P ) { //构造模式串P的next表 0002 size_t m = strlen ( P ), j = 0; //“主”串指针 0003 int* N = new int[m]; //next表 0004 int t = N[0] = -1; //模式串指针 0005 while ( j < m - 1 ) 0006 if ( 0 > t || P[j] == P[t] ) { //匹配 0007 j ++; t ++; 0008 N[j] = t; //此句可改进... 0009 } else //失配 0010 t = N[t]; 0011 return N; 0012 }