#include<stdio.h>
//#include<string.h>
//#include<math.h>
#include<stdlib.h>
//函数结果状态代码
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define NULL 0
#define MAXSIZE 100
#define MAXLEN 255
#define CHUNKSIZE 80//块的大小
//Status是函数的类型,其值是函数结果状态代码
typedef int Status;
//声明结点的类型和指向结点的指针类型
//顺序存储
typedef struct{
char ch[MAXLEN+1];//存储串的一堆数组
int length;//串的当前长度
}SString;
//链式存储
typedef struct Chunk{
char ch[CHUNKSIZE];
struct Chunk *next;
}Chunk;
typedef struct{
Chunk *head,*tail;//串的头指针、尾指针
int length;//串的当前长度
}LString;//字符串的块链结构
//BF算法
int Index_BF(SString S,SString T){//S主串、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;//因为匹配位置是从1开始的,所以i-j+1只能返回到原来的i的位置,要到达原来i的下一个位置要再+1
j=1;
}
}
if(j>=T.length) return i-T.length;//匹配成功,返回匹配的第一个字符下标
else return 0;//匹配失败
}
int main(){
return 0;
}