資料結構 字串

2021-10-21 15:22:41 字數 996 閱讀 3036

靜態陣列實現(順序儲存)

//串的順序儲存

#define maxlen 255 //預定義最大串長為255

typedef struct//靜態陣列實現(順序儲存)

sstring;

動態陣列實現(堆分配儲存)
typedef struct//動態陣列實現(堆分配儲存)

hstring;

初始化
void inithstring()

;

串的鏈式儲存
//串的鏈式儲存

typedef struct stringnode

stringnode,*string;

/*typedef struct stringnode

stringnode,*string;

*/

求子串
//求子串(pos起始位置,len長度 )

bool substring(sstring *sub,sstring s,int pos,int len)

比較操作
//比較操作

int strcompare(sstring s,sstring t)

//掃瞄過的所有字元都相同,則長度長的串更大

return s.length-t.length;

};

定位操作
//定位操作

int index(sstring s,int n,sstring t,int m)

;

//kmp演算法

int index_kmp(sstring s,sstring t,int next)

;

得到next陣列
//求模式串的next陣列

void get_next(sstring t,int next)

}

資料結構 字串

1 字串 include string.h include stdio.h include stdlib.h include math.h include time.h define ok 1 define error 0 define true 1 define false 0 define ma...

資料結構 字串

字串是由0個或多個字元構成的序列,可記為s a1a2a3 an 其中ai可以是字母,也可是數字或者其他字元,零個字元的串稱為空串。而字串的順序結構就是用簡單的char型別陣列來儲存沒什麼好說的,下面介紹一下bf演算法與kmp演算法 bf演算法就是比較平常的雙重迴圈,如果匹配成功打斷迴圈,否則子串的比...

資料結構 字串匹配

演算法 如下,包括暴力匹配和kmp演算法。參考 include stringmatching.h stringmatching stringmatching void stringmatching stringmatching void 返回子串t在主串s中第pos個字串之後的位置。若不存在,則返回...