串的基本操作(C )

2021-08-04 03:31:07 字數 1066 閱讀 7948

#include"iostream"

using namespace std;

//***************==串******************************

/*兩個串是否相等,必須是它們串的長度以及它們各個對應位置的字元都相等時,才算是相等.

串的順序儲存結構的缺點是字串的截斷,截斷就是超過預定義長度的串值被捨去.*/

//*****====串的順序儲存**********=

/*一般t[0]存放串的大小*/

const int maxsize = 40;

struct stringtype;};

/*輸出字串t*/

bool stringvisit(const stringtype *t)

else }

/*生成乙個其值為chars的串t*/

bool strcreate(stringtype *t, char *chars)

}/* 返回串的元素個數 */

int strlength(stringtype *t)

/*串比較:

初始條件: 串s和t存在

操作結果: 若s>t,則返回值》0;若s=t,則返回值=0;若s < t,則返回值< 0 */

int strcomp(const stringtype *t, const stringtype *s)

return s->length - t->length;

}/* 用t返回s1和s2聯接而成的新串。若未截斷,則返回true,否則false */

bool contact(stringtype *t, stringtype *s1, stringtype *s2)

else }

/* 用sub返回串s的第pos個字元起長度為len的子串。 */

bool substring(stringtype *t, stringtype *sub, int pos, int len)

}//kmp模式匹配演算法

int main()

更新中.........

c語言描述 串的基本操作

串的第乙個空間儲存串長 define mixsize 100 typedef int status typedef char sstring mixsize 1 status concat sstring s3,sstring s1,sstring s2 for int i s1 0 1 imixs...

串的基本操作

include include include include define maxn 50 define ok 1 define error 0 typedef struct strnode snode void creat snode char 建立串 int getsubstr snode i...

串的基本操作

串的基本操作 前記 這一章課件裡主要講了串的屬性和一些常用的操作。課件裡面是通過偽 的方式來進行描述,這樣有利於同學們的理解,以及能夠適用於各種程式語言。下面就針對c 語言對這些基本操作做乙個具體的實現,大家在運用中可以參考。mystring.h ifndef mystring h define m...