Lang:GCC
Edit12345678910111213141516171819202122232425262728293031#include <stdio.h>#include <string.h>int next[10005];//if jth charactar failed the matchchar pat[10005];char txt[1000005];void init(char str[], int len){int i,j;memset(next,-1,(len+1)*sizeof(int));next[0] = 0;//next[1] = 0;j = 0;i = 1;while (1){//printf("i:%d j:%d\n",i,j);if (next[i] == -1){next[i] = j;}if (i == len){break;}if (str[i] == str[j]){//next[i] = j;//next[i] = j;i++;