C语言 数据结构 实验三
8591 - 计算next值
#include "stdio.h"
#include "stdlib.h"
//#include "iostream.h"
#define MAXSTRLEN 255 //用户可在255以内定义最大串长
typedef unsigned char SString[MAXSTRLEN+1]; //0号单元存放串的长度
void get_next(SString T, int next[])
{
//算法4.7
//求模式串T的next函数值并存入数组next
//请补全代码
int i=1;
int j=0;
next[1] = 0;
while(i < T[0])
{
if(0 == j || T[i] == T[j])
{
i++;
j++;
/*
if(T[i] != T[j])
{
next[i] = j;
}
else
{
next[i] = next[j];
}
*/
next[i] = j;
}
else
{
j = next[j];
}
}
}
int main()
{
int next[MAXSTRLEN];
SString S;
int n, i, j;
char ch;
scanf("%d", &n)