第三週專案3 求集合並集

2021-07-22 19:02:59 字數 2029 閱讀 8820

問題**:

/*   

*檔名稱:oo.cpp

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

*版本號:v1.0

*輸入描述:無

*程式輸出:無

*/

//注:運用之前建好的演算法庫,結合對此題演算法的進一步分析,程式如下:

#define maxsize 100

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

typedef struct list

sqlist;

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

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

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

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

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

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

void unionlist(sqlist *la,sqlist *lb,sqlist *&lc); //求兩集合並集

[cpp] view plain copy 在code上檢視**片派生到我的**片

#include #include #include "list.h"

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

void displist(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) //銷毀順序表

void unionlist(sqlist *la,sqlist *lb,sqlist *&lc) //求兩集合並集

lalength=listlength(la); //求線性表la的長度

for (i=1; i<=listlength(lb); i++)

} main.cpp:

[cpp] view plain copy 在code上檢視**片派生到我的**片

#include #include #include "list.h"

int main()

執行結果:

知識點總結:

順序表的基本運算,線性表的長度與指定位置

學習心得:

進一步學習了線性表

第三週專案3 求集合並集

檔名稱 專案3.cbp 作 者 張晗 完成日期 2015年9月25日 版 本 號 v1.0 問題描述 假設有兩個集合 a 和 b 分別用兩個線性表 la 和 lb 表示,即線性表中的資料元素即為 集合中的成員。設計演算法,用函式unionlist list la,list lb,list lc 函式...

第三週專案3 求集合並集

專案名稱 專案3 求集合並集 題目描述 標頭檔案list.h ifndef list h included define list h included define maxsize 50 include include typedef int elemtype typedef struct sql...

第三週 專案3 求集合並集

檔名稱 1 順序表list.cpp 2 順序表list.h 3 集合並集.cpp 作 者 林穎 完成日期 2016年9月16日 問題描述 假設有兩個集合 a 和 b 分別用兩個線性表 la 和 lb 表示,即線性表中的資料元素即為集合中的成員。設計演算法,用函式unionlist list la,l...