您的位置:首页 > 编程语言

KMP算法中核心的代码

2012-06-10 12:22 260 查看
#include <stdio.h>

#include <iostream>

#include <stdlib.h>

#include <string.h>

using namespace std;

void get_next(string T, int *next)

{

int i = 1, j = 0;

next[1] = 0;

while (i < atoi((char *)&T[0]))

{

//cout<<"i: "<<i<<" j:"<<j<<endl;

if (j == 0 || T[i] == T[j])

{

++i;

++j;

next[i] = j;

}

else

j = next[j];

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: