版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、二叉樹基本操作的程序?qū)崿F(xiàn)作者:nuciewth 閱讀人次:43966 文章來源:本站原創(chuàng)發(fā)布時間:2007-6-13條原帖及討論:http:/ 尸0;左中for(i=0;ilen;i+)(Lai=si+1;Lalen=0;/左前for(i=len+1;istrlen(r);i+)(Rbi-len-1=ri;Rbi-len-1=0;for(i=len+1;ilchild,La,Ra);Pre_In_order(&(*t)-rchild,Lb,Rb);else(*t=NULL;intmain()(Bintreet;charpre30=ABCDEF,in30=CBAEDF;/測試數(shù)據(jù)prin
2、tf(輸入前序遍歷序列:);scanf(%s,pre);printf(輸入中序遍歷序列:);scanf(%s,in);Pre_In_order(&t,pre,in);Posorderl(t);)#include#includetypedefstructnodeintdata;structnode*lchild,*rchild,*next;hufnode;typedefhufnode*linkhuf;/*/*/linkhufCreat_Node(intn)/創(chuàng)建一單鏈表linkhufhead,pre,p;intx;head=NULL;while(n-)scanf(%d,&x);p
3、=(linkhuf)malloc(sizeof(hufnode);p-data=x;p-lchild=NULL;p-rchild=NULL;if(NULL=head)head=p;pre=head;elsep-next=pre-next;pre-next=p;pre=pre-next;returnhead;/*huffman 樹*/linkhufinsert(linkhufroot,linkhufs)/將結(jié)點 S 插入到有序(linkhufp1,p2;if(NULL=root)root=s;else(p1=NULL;p2=root;while(p2&p2-datadata)(p1=p2
4、;p2=p2-next;s-next=p2;if(NULL=p1)(root=s;else(p1-next=s;returnroot;voidPreorder1(linkhuft)(if(t!=NULL)(printf(%-6d”,t-data);Preorder1(t-lchild);Preorder1(t-rchild);voidcreathuffman(linkhuf*root)/構(gòu)造 Huffman 樹。(linkhufs,rl,rr;while(*root&(*root)-next)(rl=*root;rr=(*root)-next;*root=rr-next;Huffman
5、root 中。s=(linkhuf)malloc(sizeof(hufnode);s-next=NULL;s-data=rl-data+rr-data;s-lchild=rl;s-rchild=rr;rl-next=rr-next=NULL;*root=insert(*root,s);intmain()linkhufroot;intn;scanf(%d,&n);root=Creat_Node(n);creathuffman(&root);Preorder1(root);printf(n);return0;/*/*按層次順序建立一棵二叉樹/*/#includeBintree.hB
6、intreeLevel_Creat()Bintreeroot,p,s;queuenode;node.front=node.rear=0;charch;ch=getchar();if(ch=)returnNULL;root=(Binnode*)malloc(sizeof(Binnode);/生成根結(jié)點root-data=ch;node.datanode.rear+=root;/用隊列實現(xiàn)層次遍歷while(node.frontdata=ch;p-lchild=s;node.datanode.rear+=s;else(p-lchild=NULL;ch=getchar();if(ch!=)(s=(Binnode*)malloc(sizeof(Binnode);s-data=ch;p-rchild=s;node.datanode.rear+=s;else
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 銷售工作安排與工作計劃
- 株洲市購房合同范本(3篇)
- 2024至2030年中國循環(huán)管道清洗劑行業(yè)投資前景及策略咨詢研究報告
- 2024至2030年中國一體化感應(yīng)調(diào)溫龍頭行業(yè)投資前景及策略咨詢研究報告
- 2024年中國全自動激光切割機市場調(diào)查研究報告
- 2024至2030年防盜工程門項目投資價值分析報告
- 第一章 物質(zhì)及其變化 測試題 高一上學(xué)期化學(xué)人教版(2019)必修第一冊
- 勤快是班主任的秘訣
- 教職工慰問制度
- 熱塑性聚氨酯彈性體相關(guān)項目投資計劃書范本
- (正式版)HGT 22820-2024 化工安全儀表系統(tǒng)工程設(shè)計規(guī)范
- 小學(xué)首屆學(xué)術(shù)節(jié)活動實施方案.docx
- 《中國歷史張騫》PPT課件
- 高中世界地理區(qū)域地理填圖
- 蚌埠明達職業(yè)培訓(xùn)學(xué)校組織架構(gòu)圖及崗位職責(zé)
- 兒科過敏性紫癜護理查房記錄
- 小學(xué)美術(shù)課件-第20課-青花盤-蘇少版-(23張PPT)ppt課件
- 構(gòu)建高效課堂專題講座
- 籌備工作報告
- 《質(zhì)量管理體系文件》ISO9001:2015質(zhì)量體系文件
- 模特法(MODAPTS)
評論
0/150
提交評論