C語言實現串的基本操作(複製,比較,插入,刪除)

2021-10-02 22:24:44 字數 1718 閱讀 3234

#include #include #include#define true 1

#define false 0

#define overflow 1

#define max_size 1024

typedef int status;

/***串的順序結構實現

typedef structseqstring;

*//**串的堆式順序儲存結構(heap)*/

typedef structheapstring;

void initstring(heapstring * str)

/**為串str賦值*/

status strassigh(heapstring *str,char * chars)

str->length = len;

return 1;

}void printstring(heapstring * str)

}status strcopy(heapstring * deststr,heapstring * srcstr)

deststr->length = srcstr->length;

return true;

}/**比較兩個字串的大小str1 == str2 返回0 ;str1 < str2 返回負數;str1 > str2 返回正數*/

status strcompare(heapstring * str1,heapstring * str2)

//字元都相等,比較字串的長度

return str1->length - str2->length;

}status concat(heapstring *deststr,heapstring *str1,heapstring *str2)

for(int i = 0;i< str2->length;i++)

deststr->length = len;

return true;

}/**擷取str字串從pos位置len長度的字元到deststr中*/

status substring(heapstring * deststr,heapstring *str,int pos,int len)

deststr->length = len;

return true;

}/**返回子串child在父串parent中的位置*/

int index(heapstring * parent,heapstring * child)

return false;

}/**從pos位置刪除len個字元*/

status strdelete(heapstring * str,int pos ,int len)

/**在str中的pos位置插入字串insertstr*/

status strinsert(heapstring * str ,int pos,heapstring * insetstr)

for(int i = 0;i < insetstr->length;i++)

str->length = len;

return true;

}/**將str中的oldstr字串替換成newstr字串*/

status replace(heapstring *str,heapstring *oldstr,heapstring *newstr)

int main()

靜態串及其基本操作(C語言實現)

bcpl basiccombinedprogamminglanguage即c語言實現 靜態串實現 include include 列印字串 void displaystr const char string printf n 返回字串長度 int strlen const char string r...

C語言實現堆的基本操作

完整 本文用c語言實現了堆的基本操作,包括 建立堆 判斷堆滿 空 插入 刪除。雖然在c 的stl中已經分裝好了堆資料結構,但是在不少的場合會用到自己寫的堆。用c 更加方便 c 使用堆!堆分為最大堆和最小堆,本文對最大堆進行了說明,最小堆可模仿寫出。include include define max...

C語言實現檔案複製

使用c語言來複製乙個檔案 包括各種型別 主流的做法有2種 1.自定義函式 2.呼叫系統api 本文介紹自定義函式的方法。檔案型別可以粗略分類為ascii型別和二進位制型別,且大多數為二進位制型別,因此本文採用 fread 和 fwrite 閒話不多說,上 c語言實現檔案複製 srcfile 原始檔 ...