練習 順序串的實現及應用

2021-08-09 16:02:58 字數 2777 閱讀 3528

#define maxlength 60

typedef struct

seqstring;

void strassign(seqstring *s,char cstr) 

/*串的賦值操作*/

int strempty(seqstring s)   

/*判斷串是否為空,串為空返回1,否則返回0*/

int strlength(seqstring s)

/*求串的長度操作*/

void strcopy(seqstring *t,seqstring s) 

/*串的複製操作.*/

int strcompare(seqstring s,seqstring t)

/*串的比較操作*/

int strinsert(seqstring *s,int

pos,seqstring t)

/*串的插入操作。在s中第pos個位置插入t分為三種情況*/

if(s->length+t.length

<=maxlength) /*第一種情況,插入子串後串長≤maxlength,即子串t完整地插入到串s中*/

/*第二種情況,子串可以完全插入到s中,但是s中的字元將會被截掉*/

else

if(pos+t.length

<=maxlength)

/*第三種情況,子串t不能被完全插入到s中,t中將會有字元被捨棄*/

else

}

int strdelete(seqstring *s,int

pos,int len)

/*在串s中刪除pos開始的len個字元*/

下面為乙個刪除字串「abcdeabdbcdaaabdecdf」中所有子串「abd」的程式。

#include

#include

#define maxlen 60

typedef struct

seqstring;

int delsubstring(seqstring *s,int

pos,int n);

void strprint(seqstring s); /*串的輸出函式宣告*/

順序串的實現

package com.lovely.string author echo lovely 2020年6月9日下午6 44 31 串的介面描述 public inte ce istring package com.lovely.string author echo lovely 2020年6月9日下午...

KMP 順序串操作練習

2016年10月14日 課下練習 整型資料最好不要用 引用傳參 include include define maxsize 100 typedef struct sqstring 初始化串 void initstring sqstring s 生成乙個與str串相等的s串 void strassi...

MongoDB練習及應用

1 建立一年級的第三個班grade 1 3,隨機新增 10 名學生,欄位有,name,age,hobbydb grade 1 3 insert 例如 2檢視一年級二班grade 1 3中的所有學生db.grade 1 3.find pretty 3檢視一年級二班grade 1 3中所有年齡14 歲的...