第七周專案1(2) 建立鏈串演算法庫

2021-08-09 20:39:01 字數 2481 閱讀 5710

/*

*all right reserved.

*檔名:main.cpp listring.h listring.cpp

*完成日期:2023年10月26日

*版本號:v1.0

**問題描述:演算法庫

*輸入描述:無

*程式輸出:見執行結果

*/main.cpp:

#include

#include "listring.h"

int main()

listring.h:

#ifndef listring_h_included

#define listring_h_included

typedef struct snode

listring;

void strassign(listring *&s,char cstr);   //字串常量cstr賦給串s

void strcopy(listring *&s,listring *t); //串t複製給串s

bool strequal(listring *s,listring *t); //判串相等

int strlength(listring *s); //求串長

listring *concat(listring *s,listring *t);  //串連線

listring *substr(listring *s,int i,int j);  //求子串

listring *insstr(listring *s,int i,listring *t) ;   //串插入

listring *delstr(listring *s,int i,int j);  //串刪去

listring *repstr(listring *s,int i,int j,listring *t);  //串替換

void dispstr(listring *s);  //輸出串

#endif // listring_h_included

listring.cpp:

#include

#include

#include "listring.h"

void strassign(listring *&s,char cstr)    //字串常量cstr賦給串s

r->next=null;

}void strcopy(listring *&s,listring *t)  //串t複製給串s

r->next=null;

}bool strequal(listring *s,listring *t)  //判串相等

if (p==null && q==null)

return true;

else

return false;

}int strlength(listring *s)  //求串長

return i;

}listring *concat(listring *s,listring *t)   //串連線

p=t->next;

while (p!=null)         //將t的所有節點複製到str

r->next=null;

return str;

}listring *substr(listring *s,int i,int j)   //求子串

r->next=null;

return str;

}listring *insstr(listring *s,int i,listring *t)     //串插入

while (p1!=null)                    //將t的所有節點複製到str

while (p!=null)                     //將*p及其後的節點複製到str

r->next=null;

return str;

}listring *delstr(listring *s,int i,int j)   //串刪去

for (k=0;knext;

while (p!=null)                 //將*p及其後的節點複製到str

r->next=null;

return str;

}listring *repstr(listring *s,int i,int j,listring *t)   //串替換

for (k=0;knext;

while (p1!=null)                //將t的所有節點複製到str

while (p!=null)                 //將*p及其後的節點複製到str

r->next=null;

return str;

}void dispstr(listring *s)   //輸出串

printf("\n");

}程式執行結果如圖所示:

反思總結:

不斷地練習串演算法庫的基本應用,明白並且運用到實踐中去。

第七周 專案2建立鏈隊演算法庫

all right reserved.檔名稱 lid.cpp 作 者 商文軻 完成日期 2015年10月日 版 本 號 v1.9 問題描述 建立鏈隊演算法庫 liqueue.h ifndef liqueue h included define liqueue h included include i...

第七周專案2 建立鏈隊演算法庫

問題及描述 檔名稱 sqqueue.cpp,main.cpp,sqqueue.h 完成日期 2015年10月12日 版本號 vc6.0 問題描述 定義鏈隊儲存結構,實現其基本運算,並完成測試。liqueue.h ifndef liqueue h included define liqueue h i...

第七周 專案二 建立鏈隊演算法庫

問題及 2015,煙台大學計算機與控制工程學院 完成日期 2015年10月12日 問題描述 定義鏈佇列儲存結構,實現其基本運算,並完成測試。ifndef sqqueue h included define sqqueue h included typedef char elemtype typede...