KMP(next)模板
为方便计算,统一从下标1开始。
class mystring
{
public:
char ch[maxsize];
int length;
};
void get_next(char *nextt,mystring &T)
{
int i = 1, j = 0;
nextt[1] = 0; //初始化
while (i < T.length)
{
if (j == 0 || T.ch[i] == T.ch[j])
{
i++, j++; nextt[i] = j
原创
2021-10-11 18:33:29 ·
80 阅读 ·
0 评论