学习目标:
串的基本操作
KMP算法的原理和代码
学习内容:
串的定长储存结构
串的变长储存结构
串的赋值
取串长度操作
串的比较操作
串连接操作
求子串操作
串清空操作
基础算法匹配
KMP算法
学习时间:
2021.4.4到2021.4.5 am12:00
学习产出:
串的定长储存结构:
//串的定长储存结构表示
typedef struct
{
char str[maxsize + 1];//maxsize表示串的最大长度 以“/0”作为结束符号 所以maxsize +1
int length;
}Str;
串的变长储存结构:
//变长分配储存结构表示
typedef struct
{
char * ch;
int length;
}Str;
串的赋值:
//赋值操作
int strassign(&Str, char* ch)
{
if (str.ch)
free(str.ch);
int len = 0;
char* c = ch;
while (*c)
{
++len;
++c;
}
if (len == 0)
{
str.ch = NULL;
str.leng = o;
return 1;
}
else
{
str.ch = (char*)malloc(sizeof(char) * (len + 1));//加1是因为“\0”
if(str.ch == NULL)
return 0;
else
{
c = ch;
for (int I = 0; I <= LEN; ++i, ++c)//<=