数据结构实验三实验报告(8)
时间:2025-07-11
时间:2025-07-11
数据结构实验报告
int KMPIndex(String S, int start, String T, int next[])
{
int i= start, j=0, v;
while(i<S.length && j<T.length)
{
if(j==-1||S.str[i]==T.str[j])
{
i++;
j++;
}
else j=next[j];
}
if(j==T.length)
v=i-T.length;
else
v=-1;
return v;
}
/*RepFun.c*/
#include<stdio.h>
#define MaxSize 100
#include"SString.h"
int Replace(String *S,int start,String T,String V)
{
int i,a;
if(S->length<V.length) return 0;
a=BFIndex(*S,start,T);
if(a!=-1)
{
Delete(S,a,T.length);
Insert(S,a,V);
return 1;
}
else return 0;
}
void main(void)
{
int start=0,b;
String S={{"I am a student"},14}, T={{"student"},7},V={{"teacher"},7}; b=Replace(&S,start,T,V);
printf("run successfully and return %d\n",b);
上一篇:2014年山东高职专科排名总表
下一篇:海鲜厨房教学设计