第3周專案2 建設「順序表」演算法庫

2021-08-08 11:52:40 字數 2769 閱讀 1182

/*    

*檔名稱:專案2 - 建設「順序表」演算法庫

*作 者:馮圓

*版 本 號:v1.0

*  問題描述:領會「0207將演算法變程式」部分建議的方法,建設自己的專業基礎設施演算法庫。這一周,建的是順序表的演算法庫。

*/

問題及**:

演算法庫包括兩個檔案: 

標頭檔案:list.h,包含定義順序表資料結構的**、巨集定義、要實現演算法的函式的宣告; 

原始檔:list.cpp,包含實現各種演算法的函式的定義 

請採用程式的多檔案組織形式,在專案1的基礎上,建立如上的兩個檔案,另外再建立乙個原始檔,編制main函式,完成相關的測試工作。 

list.h:

#define maxsize 100    

typedef int elemtype; //自定義資料型別

typedef struct list

sqlist;

void createlist(sqlist *&l,elemtype a,int n); //由a中的n個元素建立順序表

void displist(sqlist *l); //輸出線性表

bool listempty(sqlist *l); //布林型函式判斷順序表是否為空表

int listlength(sqlist *l); //求順序表長度

bool getelem(sqlist *l,int i,elemtype &e); //求順序表中某個資料元素值

int locateelem(sqlist *l,elemtype e); //按元素值查詢順序表中元素

bool listinsert(sqlist *&l,int i,elemtype e); //插入資料元素

bool listdelete(sqlist *&l,int i,elemtype &e); //刪除資料元素

void initlist(sqlist *&l); //初始化線性表

void destroylist(sqlist *&l); //銷毀順序表

list.cpp:

#include #include #include "list.h"    

void createlist(sqlist *&l,elemtype a,int n) //由a中的n個元素建立順序表

void displist(sqlist *l) //輸出線性表

bool listempty(sqlist *l) //布林型函式判斷順序表是否為空表

int listlength(sqlist *l) //求順序表長度

bool getelem(sqlist *l,int i,elemtype &e) //求順序表中某個資料元素值

int locateelem(sqlist *l,elemtype e) //按元素值查詢順序表中元素

bool listinsert(sqlist *&l,int i,elemtype e) //插入資料元素

bool listdelete(sqlist *&l,int i,elemtype &e) //刪除資料元素

void initlist(sqlist *&l) //初始化線性表

void destroylist(sqlist *&l) //銷毀順序表

main:

#include #include #include #include "list.h"

using namespace std;

int main()

;

elemtype b[5]=;

elemtype e;

int loc;

createlist(l,a,10);

cout<<"建立的順序表中各元素為:"<0) //測試能找到的情形

printf("找到了,值為8的元素是第 %d 個\n",loc);

else

printf("值為8的元素木有找到!\n");

if((loc=locateelem(l,17))>0) //測試不能找到的情形

printf("找到了,值為17的元素是第 %d 個\n",loc);

else

printf("值為17的元素木有找到!\n");

destroylist(l);

cout<<"此順序表被銷毀"<

知識點總結:

演算法庫,程式的多檔案組織

學習心得:

建立演算法庫為做題帶來了方便

第3周 專案2 建設「順序表」演算法庫

問題描述 採用程式的多檔案組織形式,在專案1的基礎上,建立標頭檔案lish.h 包含定義順序表結構的 巨集定義 要實現演算法的函式的宣告 和原始檔function.cpp 包含實現各種演算法的函式的定義 main.cpp 中的 include list.h int main createlist s...

第3周專案2 建設「順序表」演算法庫

檔名稱 專案2.cbp 作 者 孟琪琪 完成日期 2016年9月16日 版 本 號 v1.0 問題描述 請採用程式的多檔案組織形式,在專案1的基礎上,建立 如上的兩個檔案,另外再建立乙個原始檔,編制main函 數,完成相關的測試工作。輸入描述 無 程式輸出 依據各個函式而定 架構 list.h檔案 ...

第3周專案2 建設「順序表」演算法庫

問題及 檔名稱 2.cpp 作 者 王修文 完成日期 2016年9月17日 版 本 號 v1.0 問題描述 請採用程式的多檔案組織形式,在專案1的基礎上,建立 如上的兩個檔案,另外再建立乙個原始檔,編制main函 數,完成相關的測試工作。輸入描述 無 程式輸出 標頭檔案list.h define m...