第三週專案一(2)

2021-08-08 13:21:34 字數 1693 閱讀 1560

/*

煙台大學計算機學院

檔名稱:xm1.cpp

完成日期:2023年9月20日

問題描述:順序表建立,查詢

輸入描述:無

輸出描述:順序表元素,順序表位置

*/#include 

#include 

#define maxsize 50//儲存空間大小巨集定義

typedef

int elemtype;  //定義elemtype為int

typedef

struct

sqlist;  

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

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

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

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

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

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

int main()//主函式

;  elemtype a;  

elemtype b;  

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");  

return 0;  

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

//建立線性表

void displist(sqlist *l)  

//輸出線性表

bool listempty(sqlist *l)  

//判斷為空表

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

int listlength(sqlist *l)  

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

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

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

第三週專案(2)

問題及 main。cpp all right reserved.檔名稱 l1.cpp 完成日期 2016年9月22日 版本號 v1.0 問題描述 已知l1和l2分別指向兩個單鏈表的頭結點,且已知其長度分別為m n,請設計演算法將l2連線到l1的後面。實現這個演算法,完成測試,並分析這個演算法的複雜度...

第三週專案2

煙台大學計算機學院 檔名稱 xm2.cpp 完成日期 2017年9月17日 問題描述 順序表建立,查詢,插入,刪除多檔案 輸入描述 無 輸出描述 順序表元素,查詢的元素,順序表位置 list.h ifndef list h included define list h included define...

第三週專案一

include include define maxsize 50 maxsize將用於後面定義儲存空間的大小 typedef int elemtype elemtype在不同場合可以根據問題的需要確定,在此取簡單的int typedef struct sqlist 自定義函式宣告部分 void c...