KMP中next数组实现
#include <iostream>
using namespace std;
int main()
{
char a[] = {'a','b','c','d','a','b','d'};
int next[7];
next[0] = 0;
int j = 0;
int i = 1;
while( i<7 ){
if(a[next[i-1]] == a[i]){
next[i] = next[i-1] +1;
}else if(a[0] == a[i]){
next[i] = 1;
}else{
next[i] = 0;
}
i++;
}
while( j < 7){
cout << next[j++] << endl;
}
return 0;
}