




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(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ì)二叉排序樹(shù)查找C語(yǔ)言代碼1含測(cè)試序列#include stdio. h #include stdlib h #include ,zmalloc h typedef int KeyType; typedef structKeyType key;DataType;typedef struct node DataType data;struct node *leftChild; struct node *rightChild; BiTreeNode;BiTreeNode *root=NULL; DataType a20, item; int i,n, num=0;/*査找*/void
2、 Search(BiTreeNode *root, DataType item)BiTreeNode *p;辻(root!=NULL)p=root;while(p!=NULL)if (p-data key二二item. key) break;num=l;if(item. keyp-data. key) p=p-rightChiId;elsep = pleftChild;if(p二二NULL)num二0;if (numl)for(i=0;idata keyleftChiId;p=(BiTreeNode *)malloc(sizeof(BiTreeNode);if(p二二NULL)printf(,
3、zLack of space!);exit(l);p-data=item;p-leftChild二NULL;p-rightChild=NULL;if(parent二二NULL) *root=p;else if(item. keydata key) parent-leftChild=p;else parent-rightChi1d=p;return 1;/*插入數(shù)組*/void InsertN()printf (Please enter some integer:nz,);for(i=0;i20;i+)scanf (,/%d,/,&ai);if (ai. key=-l) /*判斷是否非數(shù)字*/n
4、=i;break;else if(ail. key0. n);i;if (i=19) n 二 20;break;printf (,znThe number you entered are:n,z):for(i=0;ileftChiId!二NULL)InTraverse(root-leftChild);printf (z/%d , root-data key);if(root-rightChiId!=NULL)InTraverse(root-rightChiId) ; /*刪除*/ /*DataType item*/void Destroy ()/*BiTreeNode *root:辻(*roo
5、t)!=NULL&(*root)-leftChild!=NULL)Destroy(&(*root)-leftCh訂d); if(*root)!=NULL&(*root)-Might Chi Id!二NULL)Destroy(&(*root)-rightChiId); free(*root);*/printf (Destory has been finished!z/);/*打印二叉樹(shù)*/void PrintBiTree(BiTreeNode *bt, int n) if (bt二二NULL)return;PrintBiTree(bt-rightChild, n+1); for(i二0;i二0)
6、printf C”);printf(%dn, bt-data);PrintBiTree(bt-leftChiId, n+1) ; /*主函數(shù)*/void main()int d, t二0;doprintf(n);printfC 1. Insert); /*y第二次插入的重復(fù)數(shù)字沒(méi)有被記錄,記錄了新的數(shù)字,相同數(shù)值被忽略*/printf C 2. Searchll);printf (,z 3. Destroyn);printf C 4. Printnz,);printf C 5. InTraversen); /*y*/printf C 6. Exit! nnz/);printf (Input c
7、ommand number:n,z): scanf (%d, &d);switch(d)case 1: InsertNO ; break;case 2:printf Cn Search number: n,z):scanf&item key);Search (root, item);break;case 3: /*判斷是否存在該數(shù)值*/printf (Destroy number: nz/); scanf (,z%d,z, &item. key);Search(root, item);if (num=0)printf (Destroy could not be done n);break;el
8、seDestroy ();break;case 4: PrintBiTree(root, 0): break;case 5: InTraverse (root): break;case 6: t=l: break;default: printf(The number should between 1 and 6. n); while(!t);測(cè)試序列二義排療;樹(shù)查找1 Insert2. Search3. Destroy4. Print3. InTraverse6. Exit!Input command number:Please enter some integer:1105032576940
9、88-1The number you entered are:10 50 32 5 76 9 40 881 Insert2. Search3. Destroy4. Print5. InTraverse6. Exit!Input command number:48876504032一一一1051. Insert2. Search3. Destroy4. Print3. InTraverse6. Exit!Input command number: 2Search number: 9Element 9 exists in a5J1. Insert2. Search3. Destroy4. Print5. InTraverse6. Exit!Input command number: 1Please enter some integer:1206-1The number you entered are:6. Exit!120 61.Insert2.Search3.Destroy4.Print5.InTraverse6.Exit!Input command number: 41208876504032一10一 01.Insert2.Search
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(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ě)幼兒園發(fā)展新篇章計(jì)劃
- 重大建設(shè)項(xiàng)目的安全檢查計(jì)劃
- 2025年貓爬架項(xiàng)目發(fā)展計(jì)劃
- 2025年板臥式電除塵器項(xiàng)目合作計(jì)劃書(shū)
- 2025年密封用填料及類(lèi)似品項(xiàng)目建議書(shū)
- 實(shí)施均衡發(fā)展的人口政策
- 醫(yī)療健康管理服務(wù)協(xié)議
- 藝術(shù)品交易與展示項(xiàng)目投資合同
- 擔(dān)保期權(quán)合同
- 西游記中的人物形象賞析與解讀
- 人教版(2024新版)七年級(jí)上冊(cè)英語(yǔ)各單元重點(diǎn)語(yǔ)法知識(shí)點(diǎn)講義
- 安全閥校驗(yàn)標(biāo)準(zhǔn)
- 耳穴壓豆課件
- 建筑制圖與識(shí)圖教學(xué)課件:第八章 結(jié)構(gòu)施工圖
- 湘教版三年級(jí)美術(shù)下冊(cè)教案全冊(cè)
- (高清版)DB15∕T 3585-2024 高標(biāo)準(zhǔn)農(nóng)田施工質(zhì)量評(píng)定規(guī)程
- 試油(氣)HSE作業(yè)指導(dǎo)書(shū)
- 重癥監(jiān)護(hù)-ICU的設(shè)置、管理與常用監(jiān)測(cè)技術(shù)
- 法律顧問(wèn)服務(wù)投標(biāo)方案(完整技術(shù)標(biāo))
- 中醫(yī)藥三方合作協(xié)議書(shū)范本
- 2024年《動(dòng)漫藝術(shù)概論》自考復(fù)習(xí)題庫(kù)(附答案)
評(píng)論
0/150
提交評(píng)論