已知模式串t = “abcaabbabcab”,写出用KMP算法求得的每个字符对应的next和nextval函数值。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLEN 255
typedef struct {
char *ch;
int length;
}SString;
void getNext(SString t,int next[]){
int i = 1,j = 0;
next[1] = 0;
while(i < t.length){
if(j==0 || t.ch[i] == t.ch[j]){
i++;j++;
next[i] = j;
}else{
j = next[j];
}
}
}
void getNextVal(SString t,int nextval[]){
int i = 1,j = 0;
nextval[1] = 0;
while(i < t.length){
if(j==0 ||t.ch[i] == t.ch[j]){
i++;j++;
if(t.ch[i] != t.ch[j])nextval[i] = j;
else nextval[i] = nextval[j];
}else{
j = nextval[j];
}
}
}
void InitString(SString *t){
(*t).ch = (char*)malloc(