#include <stdio.h>
#define MaxSize 100
//定义
typedef struct{
char ch[MaxSize];
int length;
}SString;
//朴素模式匹配算法 ,主串S,辅串T ,最坏时间复杂度:O(mn)
int Index(SString S,SString T){
int i=1,j=1;
while(i<=S.length&&j<=T.length){
if(S.ch[i]==T.ch[j]){
++i;
++j;
}
else{
i=i-j+2;
j=1;
}
}
if(j>T.length)
return i-T.length;
else
return 0;
}
//KMP算法,最坏时间复杂度:O(m+n) ,主串指针不会变小
int Index_KMP(SString S,SString T,int next[]){
int i=1,j=1;
if(i<=S.length&&j<=T.length){
while(j==0||S.ch[i]==T.ch[j]){
++i;
++j;
}
}
else{
j=next[j]; //next数组需要提前手动求出
}
if(j>T.length)
return i-T.length;
else
return 0;
}
int main(){
}