无码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)的評論 (共 條)

分享到微博請遵守國家法律
隆尧县| 绍兴县| 同德县| 阿克陶县| 鹤岗市| 阳江市| 平罗县| 金川县| 太仆寺旗| 庐江县| 县级市| 湟源县| 芮城县| 东辽县| 新兴县| 共和县| 呼伦贝尔市| 射洪县| 比如县| 凤凰县| 和平县| 洛浦县| 仁寿县| 通城县| 夏邑县| 淅川县| 巴彦淖尔市| 长宁区| 陆良县| 阿克陶县| 法库县| 福海县| 蓬莱市| 宁城县| 宣化县| 顺平县| 余姚市| 沙田区| 林周县| 阳曲县| 乐平市|