第三週專案2 建設「順序表」演算法庫

2021-07-22 16:26:11 字數 2525 閱讀 1095

問題及**:

/*

*檔名稱:1.cpp

*完成日期:2023年9月12日

*版本號:v1.0

*問題描述:用函式實現順序表的10個基本運算(見下),並用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); //銷毀順序表

fun.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.cpp:

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

using namespace std;

int main()

; elemtype b[5]=;

elemtype e;

int loc;

createlist(l,a,10);

cout<

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<

執行結果:

知識點總結:

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

心得體會:

在之前基本運算的基礎上,組織了多檔案並建立了自己的專業演算法庫,為今後解決各種更複雜的問題帶來了便利。

第三週 專案2 建設順序表演算法庫

檔名稱 cpp.cpp 作者 王超 完成日期 2015.9.18 問題描述 建設順序表演算法庫 include include define maxsize 50 typedef int elemtype typedef struct sqlist void createlist sqlist l,...

第三週專案2 建設「順序表」演算法庫

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

第三週 專案2 建設「順序表」演算法庫

01.04.檔名稱 list.cpp 05.作 者 蘇凱祺 06.完成日期 2014年10月9號 07.版 本 號 v1.0 08.問題描述 建設 順序表 的演算法庫 09.list.h ifndef list h included define list h included define max...