




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、二叉樹基本操作的程序?qū)崿F(xiàn)作者:nuciewth 閱讀人次:43966 文章來源:本站原創(chuàng)發(fā)布時(shí)間: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é)點(diǎn) 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é)點(diǎn)root-data=ch;node.datanode.rear+=root;/用隊(duì)列實(shí)現(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)容里面會(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)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2.2社會(huì)主義制度在中國的確立 課件 統(tǒng)編版高中思想政治必修1中國特色社會(huì)主義
- 納稅評(píng)估工作總結(jié)十篇
- 老年日??祻?fù)護(hù)理課件
- 老年護(hù)理課件題目
- 老年人慢性病課件
- 老年中醫(yī)課件制作
- 通信設(shè)備車間使用權(quán)及技術(shù)轉(zhuǎn)讓合同模板
- 保險(xiǎn)理賠責(zé)任限制條件合同
- 大學(xué)國家安全教育考試試題及答案
- 輔警培訓(xùn)課件
- 《產(chǎn)科危急重癥早期識(shí)別中國專家共識(shí)(2024年版)》解讀課件
- 中醫(yī)外科一般護(hù)理常規(guī)
- 2025至2030中國礦用卡車行業(yè)發(fā)展趨勢分析與未來投資戰(zhàn)略咨詢研究報(bào)告
- 氟骨癥課件教學(xué)課件
- 腳手架知識(shí)試題集及答案
- 2025年河南省中考數(shù)學(xué)試題卷(含官方答案)
- SL631水利水電工程單元工程施工質(zhì)量驗(yàn)收標(biāo)準(zhǔn)第1部分:土石方工程
- (正式版)HGT 22820-2024 化工安全儀表系統(tǒng)工程設(shè)計(jì)規(guī)范
- 第3課 象外之境-中國傳統(tǒng)山水畫 說課稿- 高中美術(shù)人教版(2019)美術(shù)鑒賞
- 第2課《說和做》課件(共30張ppt) 部編版語文七年級(jí)下冊
- 數(shù)獨(dú)題目大全及答案
評(píng)論
0/150
提交評(píng)論