




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)專 業(yè):XXX班 級(jí):XXX學(xué) 號(hào):XXX姓 名:XXX日期: 年 月 日一、 需求分析動(dòng)態(tài)查找表在查找過程中可改變表的狀態(tài),即可插入或刪除數(shù)據(jù),它適合用在表的內(nèi)容要經(jīng)常變化的情況下,如飛機(jī)航班的旅客信息表。二、 概要設(shè)計(jì)1、 主界面設(shè)計(jì) 為了實(shí)現(xiàn)對(duì)二叉排序樹各功能的管理,設(shè)計(jì)一個(gè)多菜單的菜單,方便用戶使用本系統(tǒng)。本系統(tǒng)主控菜單運(yùn)行界面如下圖所示。2、 存儲(chǔ)結(jié)構(gòu)設(shè)計(jì)本系統(tǒng)選取二叉鏈表作為二叉排序樹的存儲(chǔ)結(jié)構(gòu)3、 系統(tǒng)功能設(shè)計(jì)本系統(tǒng)設(shè)置了5個(gè)資功能的設(shè)計(jì),如下:(1) 建立二叉排序樹可以一次輸入多個(gè)數(shù)據(jù),建立二叉排序樹。但是只能建立一次,一旦選擇輸入后就會(huì)被鎖定,不能再次輸入。通
2、過CreateBST(BiTree & T)函數(shù)實(shí)現(xiàn)。(2) 查找需求的數(shù)據(jù)輸入一個(gè)數(shù)據(jù)進(jìn)行查找,用SearchBST (BiTree T, KeyType key)函數(shù)來實(shí)現(xiàn)(3) 插入一個(gè)數(shù)據(jù)根據(jù)給定的數(shù)據(jù)進(jìn)行查找,若沒有,則插入,用InsertBST(BiTree &T, TElemType e)函數(shù)來實(shí)現(xiàn)(4) 刪除數(shù)據(jù)選擇一個(gè)數(shù)據(jù)進(jìn)行刪除操作DeleteBST(BiTree &T, KeyType key)(5) 遍歷輸出二叉排序樹通過三種順序進(jìn)行遍歷,可以選擇先,中,后序的方式,PreOrderTraverse(BiTree T),InOrderTraverse(BiTree T)
3、, PostOrderTraverse(BiTree T)三、 詳細(xì)設(shè)計(jì)1、 數(shù)據(jù)類型定義本系統(tǒng)采用鏈?zhǔn)浇Y(jié)構(gòu)存儲(chǔ)信息。結(jié)點(diǎn)定義如下:typedef structKeyType key;TElemType;2、 系統(tǒng)主要子函數(shù)詳細(xì)設(shè)計(jì)建立二叉排序樹:Status CreateBST(BiTree & T)int k;TElemType a10;cout請(qǐng)輸入要輸入的個(gè)數(shù):k;cout請(qǐng)依次輸入這些數(shù),回車結(jié)束:endl;for(int i=0;iai.key;InitDSTable(T);for(int m=0;mk;m+)InsertBST(T, am);return TRUE;遍歷輸出:vo
4、id Visit(TElemType a) cout data); PreOrderTraverse(T-lchild); PreOrderTraverse(T-rchild); void InOrderTraverse(BiTree T) if (T) InOrderTraverse(T-lchild); Visit(T-data); InOrderTraverse(T-rchild); void PostOrderTraverse(BiTree T) if (T) PostOrderTraverse(T-lchild); PostOrderTraverse(T-rchild); Visit
5、(T-data); 四、 測(cè)試分析(一) 在建立二叉排序樹上,應(yīng)該輸入一次,這樣才能有序有效,故,采用一開即閉的操作(二) 輸入時(shí),應(yīng)該先給出循環(huán)次數(shù),這樣便于操作(三) 進(jìn)行2至5的操作時(shí),必須先建立二叉排序樹五、 使用說明1) 本程序執(zhí)行文件為“test.exe”。2) 進(jìn)入本系統(tǒng)之后,隨即顯示系統(tǒng)主菜單。用戶可以鍵入對(duì)應(yīng)功能的數(shù)字選項(xiàng),執(zhí)行對(duì)應(yīng)的功能3) 本程序沒有直接修改的功能,可以通過查找,刪除,插入完成此功能4) 根據(jù)提示進(jìn)行各項(xiàng)操作六、 測(cè)試結(jié)果1. 在主菜單下,用戶輸入1并回車,然后按照提示建立二叉排序樹,運(yùn)行結(jié)果如下圖:2. 在主菜單下,用戶輸入2并回車,然后按照提示查詢數(shù)據(jù)
6、,運(yùn)行結(jié)果如下圖:3. 在主菜單下,用戶輸入3并回車,然后按照提示插入數(shù)據(jù),運(yùn)行結(jié)果如下圖:4. 在主菜單下,用戶輸入4并回車,然后按照提示刪除數(shù)據(jù),運(yùn)行結(jié)果如下圖:5. 在主菜單下,用戶輸入5并回車,然后按照提示遍歷輸出,運(yùn)行結(jié)果如下圖:6. 在主菜單下,用戶輸入0并回車,然后按照提示進(jìn)行退出,運(yùn)行結(jié)果如下圖:代碼:#include#includeusing namespace std;#define FALSE 0#define TRUE 1#define NULL 0#define OVERFLOW -2#define EQ(a,b) (a)=(b)#define LT(a,b) (a)
7、data.key) return T; else if (LT(key, T-data.key) return SearchBST(T-lchild, key); else return SearchBST(T-rchild, key); Status SearchBST(BiTree T, KeyType key, BiTree f, BiTree &p) if (!T) p = f; return FALSE; else if (EQ(key, T-data.key) p = T; return TRUE; else if (LT(key, T-data.key) return Searc
8、hBST(T-lchild, key, T, p); else return SearchBST(T-rchild, key, T, p); Status InsertBST(BiTree &T, TElemType e) BiTree p,s; if (!SearchBST(T, e.key, NULL, p) s = (BiTree)malloc(sizeof(BiTNode); s-data = e; s-lchild = s-rchild = NULL; if (!p) T = s; else if (LT(e.key, p-data.key) p-lchild=s; else p-r
9、child = s; return TRUE; else return FALSE; Status Delete(BiTree &p) BiTree q, s; if (!p-rchild) q = p; p = p-lchild; free(q); else if (!p-lchild) q = p; p = p-rchild; free(q); else q = p; s = p-lchild; while (s-rchild) q = s; s = s-rchild; p-data = s-data; if (q != p) q-rchild = s-lchild; else q-lch
10、ild = s-lchild; free(s); return TRUE; / DeleteStatus DeleteBST(BiTree &T, KeyType key) if(T) if (EQ(key, T-data.key) return Delete(T); else if (LT(key, T-data.key) return DeleteBST(T-lchild, key); else return DeleteBST(T-rchild, key); else return FALSE;Status CreateBST(BiTree & T)int k;TElemType a10
11、0;cout請(qǐng)輸入要輸入的個(gè)數(shù):k;cout請(qǐng)依次輸入這些數(shù),回車結(jié)束:endl;for(int i=0;iai.key;InitDSTable(T);for(int m=0;mk;m+)InsertBST(T, am);return TRUE;void Visit(TElemType a) cout data); PreOrderTraverse(T-lchild); PreOrderTraverse(T-rchild); void InOrderTraverse(BiTree T) if (T) InOrderTraverse(T-lchild); Visit(T-data); InOrd
12、erTraverse(T-rchild); void PostOrderTraverse(BiTree T) if (T) PostOrderTraverse(T-lchild); PostOrderTraverse(T-rchild); Visit(T-data); void Interface1()cout*歡迎進(jìn)行二叉排序樹的操作*endl;coutendl;cout* 1、創(chuàng)建 * 2、查找 *endl;cout* 3、插入 * 4、刪除 *endl;cout* 5、遍歷 * 0、退出 *endl;coutendl;cout*endl;coutendl;void Interface2(
13、)cout*歡迎進(jìn)行遍歷操作*endl;coutendl;cout* 1、先序 *endl;cout* 2、中序 *endl;cout* 3、后序 *endl;cout* 0、退出 *endl;coutendl;cout*endl;coutendl;int main()Interface1();int flag=0;int choice;int on_off=1;BiTree BST;InitDSTable(BST);while(1)cout選擇你要進(jìn)行的操作(0-5):choice;switch(choice)case 1:system(cls);Interface1();if(on_off
14、)flag=CreateBST(BST);on_off=0;else cout已經(jīng)創(chuàng)建,不可重復(fù)操作!endl;coutendl;break;case 2:system(cls);Interface1(); if(flag=1)KeyType search;BiTree L;InitDSTable(L);coutsearch;L=SearchBST(BST,search);if(L)cout這個(gè)數(shù)為:data.keyendl;else cout查無該數(shù)據(jù)!endl;else cout二叉排序樹尚未建立,先建立它!endl;coutendl;break;case 3:system(cls);In
15、terface1(); if(flag=1)TElemType insert;int mark1;cout請(qǐng)輸入要插入的數(shù)據(jù)insert.key;mark1=InsertBST(BST,insert);if(mark1) cout數(shù)據(jù)庫沒有該數(shù)據(jù),插入成功!endl;else cout數(shù)據(jù)庫已有該數(shù)據(jù)!endl;else cout二叉排序樹尚未建立,先建立它!endl;coutendl;break;case 4:system(cls);Interface1(); if(flag=1)KeyType remove;intmark2;cout請(qǐng)輸入要?jiǎng)h除的數(shù)據(jù)remove;mark2=Delete
16、BST(BST,remove);if(mark2) cout刪除成功!endl;else cout刪除不成功!endl;else cout二叉排序樹尚未建立,先建立它!endl;coutendl;break;case 5:system(cls); if(flag=1)int sign=1;while(sign)Interface2();int serial_number;cout請(qǐng)輸入一個(gè)順序(1-3):serial_number;switch(serial_number)case 1:system(cls);cout先序遍歷的結(jié)果為:endl;PreOrderTraverse(BST);coutendl;coutendl;break;case 2:system(cls);cout中序遍歷的結(jié)果為:endl;InOrderTraverse(BST);coutendl;coutendl;break;case 3:system(cls);cout后序遍歷的結(jié)果為:endl;PostOrderTraverse(BST);coutendl;coutendl;break;cas
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 離婚協(xié)議補(bǔ)充條款法律咨詢合同
- 商業(yè)綜合體車位使用權(quán)轉(zhuǎn)讓與商業(yè)運(yùn)營協(xié)議
- 拆遷安置補(bǔ)償與社區(qū)安全合同模板
- 生態(tài)草場(chǎng)承包租賃管理合同范本
- 車輛保險(xiǎn)理賠與購銷合作合同范本
- 綜合性離婚財(cái)產(chǎn)分配及子女撫養(yǎng)協(xié)議標(biāo)準(zhǔn)范本
- 水產(chǎn)養(yǎng)殖魚塘承包合同范本
- 高級(jí)采購談判技巧與合同簽訂培訓(xùn)協(xié)議
- 高端餐廳廚師聘用與廚藝競(jìng)賽合作協(xié)議
- 能源采購與法務(wù)碳排放管理合同
- 連續(xù)箱梁裂縫處治方案
- 2022年河南項(xiàng)城市事業(yè)單位引進(jìn)緊缺高層次人才16名筆試備考題庫及答案解析
- 2023年無錫宜興市小升初英語考試模擬試題及答案解析
- 沃爾瑪收貨規(guī)定
- 2022年丹東市元寶區(qū)社區(qū)工作者招聘筆試題庫及答案解析
- 小學(xué)道德與法治人教五年級(jí)上冊(cè)(統(tǒng)編)第三單元我們的國土我們的家園-愛國教案
- 藝術(shù)欣賞完整版課件全套ppt教程(最新)
- GB∕T 2518-2019 連續(xù)熱鍍鋅和鋅合金鍍層鋼板及鋼帶
- 土地項(xiàng)目測(cè)算表_模板
- 教育培訓(xùn)機(jī)構(gòu)輔導(dǎo)老師月度績(jī)效考核表(KPI)
- 立式水輪機(jī)組軸線調(diào)整及導(dǎo)軸承的間隙分配ppt課件
評(píng)論
0/150
提交評(píng)論