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

2021-08-08 10:46:19 字數 2672 閱讀 6594

問題及**:

main.cpp

/*

* 檔名: main.cpp

* 作 者:王效傑

*完成日期:2023年 9月 18日;

* 第三週 :課後上機實踐專案二

*/#include #include #include "list.h"

int main()

; createlist(sq, x, 6);

displist(sq);

printf("表長度:%d\n", listlength(sq));

if(getelem(sq,4,a))//測試在範圍內

else

if(getelem(sq, 3, a)) //測試不在範圍內的情形

printf("找到了第3個元素值為:%d\n", a);

else

printf("第3個元素超出範圍!\n");

if(b=locateelem(sq,3)>0)//測試找到

else

if((b=locateelem(sq, 17))>0) //測試不能找到的

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

else

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

printf("初始化插入之後\n");

initlist(sq);

listinsert(sq, 1, 5);

listinsert(sq, 2, 3);

listinsert(sq, 1, 4);

displist(sq);

return 0;

}

list.cpp

#include #include #include "list.h"

//用陣列建立線性表

void createlist(sqlist *&l, elemtype a, int n)

//初始化線性表initlist(l)

void initlist(sqlist *&l) //引用型指標

//銷毀線性表destroylist(l)

void destroylist(sqlist *&l)

//判定是否為空表listempty(l)

bool listempty(sqlist *l)

//求線性表的長度listlength(l)

int listlength(sqlist *l)

//輸出線性表displist(l)

void displist(sqlist *l)

//求某個資料元素值getelem(l,i,e)

bool getelem(sqlist *l,int i,elemtype &e)

//按元素值查詢locateelem(l,e)

int locateelem(sqlist *l, elemtype e)

//插入資料元素listinsert(l,i,e)

bool listinsert(sqlist *&l,int i,elemtype e)

//刪除資料元素listdelete(l,i,e)

bool listdelete(sqlist *&l,int i,elemtype &e)

list.h

#ifndef list_h_included

#define list_h_included

#define maxsize 50

typedef int elemtype;

typedef struct

sqlist;

void createlist(sqlist *&l, elemtype a, int n);//用陣列建立線性表

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

void destroylist(sqlist *&l);//銷毀線性表destroylist(l)

bool listempty(sqlist *l);//判定是否為空表listempty(l)

int listlength(sqlist *l);//求線性表的長度listlength(l)

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

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

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

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

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

#endif

執行結果:

知識點總結:

多檔案組織,順序表的應用。

學習心得:

學習了順序表的應用,在組織多檔案的時候出現了一些未知錯誤,重新建立檔案後又消失了。

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

問題描述及 檔名稱 123.cpp 完成日期 2016.9.16 標頭檔案 list.h,包含定義順序表資料結構的 巨集定義 要實現演算法的函式的宣告 原始檔 list.cpp,包含實現各種演算法的函式的定義 1.list.h的 include include define maxsize 50 t...

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

檔名稱 aa 作 者 申鵬鵬 完成日期 2016年9月17日 問題描述 本文為演算法庫中的第乙個,針對線性表中的順序儲存結構,實現各種基本運算。演算法庫包括兩個檔案 標頭檔案 list.h,包含定義順序表資料結構的 巨集定義 要實現演算法的函式的宣告 原始檔 list.cpp,包含實現各種演算法的函...

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

檔名稱 llh.cpp 作 者 李良涵 完成日期 2016年9月18日 版 本 號 v1.0 問題描述 建立順序表的演算法庫 輸入描述 無 程式輸出 依據各個函式而定 問題及 main.cpp include list.h int main createlist sq,x,6 displist sq...