无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

王道計算機考研 數(shù)據(jù)結(jié)構(gòu)

2023-07-12 17:59 作者:冷漠的學(xué)習(xí)機器G  | 我要投稿

void nextArr(const char* sub, int* next)

{

int len = strlen(sub);

next[0] = -1;

next[1] = 0;

int i = 2;

int k = 0;

while (i < len)

{

if (k == -1 || sub[i - 1] == sub[k])

{

next[i] = k + 1;

k++;

i++;

}

else

{

k = next[k];

}

}

}

int * nextValArr(int* next,int lenSub,const char?*sub,int *nextVal)

{

nextVal[0] = -1;

for (int j = 1; j < lenSub; j++)

{

if (sub[j] == sub[next[j]])

{

nextVal[j] = next[next[j]];

}

else

{

nextVal[j] == next[j];

}

}

return nextVal;

}

int Kmp(const char* str, const char* sub)

{

if (sub == "")

return 0;

int i = 0;

int j = 0;

int lenStr = strlen(str);

int lenSub = strlen(sub);

if (lenSub == 1)

{

for (int a = 0; a < lenStr; a++)

{

if (str[a] == sub[0])

return a;

}

return -1;

}

int* next = (int*)malloc(sizeof(int) * lenSub);

nextArr(sub, next);

int* nextVal = (int*)malloc(sizeof(int) * lenSub);

nextVal = nextValArr(next, lenSub,sub,nextVal);

while (i < lenStr && j < lenSub)

{

if ((j == -1) || str[i] == sub[j])

{

i++;

j++;

}

else

{

j = nextVal[j];

}

}

free(next);

if (j >= lenSub)

{

return i - j;

}

return -1;


}

自學(xué)一下午自己寫的KMP

王道計算機考研 數(shù)據(jù)結(jié)構(gòu)的評論 (共 條)

分享到微博請遵守國家法律
崇明县| 禄丰县| 阜阳市| 敦化市| 浙江省| 泰和县| 松阳县| 信丰县| 仙居县| 鸡东县| 冀州市| 白沙| 白朗县| 凤翔县| 仪陇县| 宝兴县| 万盛区| 东安县| 富民县| 奉贤区| 玉林市| 乌拉特前旗| 庐江县| 庆云县| 运城市| 南江县| 兰坪| 襄城县| 稷山县| 友谊县| 榆林市| 安远县| 金平| 广饶县| 民丰县| 濉溪县| 万山特区| 沾化县| 禄劝| 马边| 阿城市|