二叉樹基本操作的程序?qū)崿F(xiàn)_第1頁
二叉樹基本操作的程序?qū)崿F(xiàn)_第2頁
二叉樹基本操作的程序?qū)崿F(xiàn)_第3頁
二叉樹基本操作的程序?qū)崿F(xiàn)_第4頁
二叉樹基本操作的程序?qū)崿F(xiàn)_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論