//http://www.cppblog.com/oosky/archive/2006/07/06/9486.html
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
void print(const char* T, int next[])
{
//这里是我加的显示部分
int i = 0;
while ( T[i/*+1*/] != '\0' )
{
cout<<i<<"\t";
++i;
}
i = 0;
cout<<endl;
while ( T[i/*+1*/] != '\0' )
{
cout<<T[i]<<"\t";
++i;
}
cout<<endl;
i = 0;
while ( T[i/*+1*/] != '\0' )
{
cout<<next[i]<<"\t";
++i;
}
cout<<endl;
}
void get_nextval3(const char* T, int next[])
{
next[0]= -1;
int k=-1,j=0;
while(T[j] != '\0')
{
if(k!= -1 && T[k]!= T[j] )
k=next[k];
++j;++k;
if(T[k]== T[j])
next[j]=next[k];
else
next[j]=k;
}
print(T, next);
}
void get_nextval2(const char* T, int next[])
{
int k = -1, j = 0;
next[0] = -1;
while(T[j + 1] != '\0')
{
if(k == -1 || T[j] == T[k])
{
j++;