标签:kmp
next数组是加速字符串匹配的的一个重要工具
以下是next数组的实现过程
int* getnext(string &T) { int length = T.length(); int *next = new int[length]; next[0] = -1; next[1] = 0; int i = 1; int j = 0; while(i<length) { if(T[i] == T[j]) { next[++i] = ++j; } else if(j>0) { j = next[j]; } else { next[++i] = 0; } } return next; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:kmp
原文地址:http://blog.csdn.net/chenmengmengx/article/details/46700927