#include<stdio.h> #define TREEMAX 100 typedef struct BT { char data; BT *lchild; BT *rchild; }BT; BT *CreateTree(); void Preorder(BT *T); void Postorder(BT *T); void Inorder(BT *T); void Leafnum(BT *T); void Nodenum(BT *T); int TreeDepth(BT *T); int count=0; void main() { BT *T=NULL; char ch1,ch2,a; ch1='y'; while(ch1=='y'||ch1=='y') { printf("\n"); printf("\n\t\t 二叉樹子系統(tǒng)"); printf("\n\t\t*****************************************"); printf("\n\t\t 1---------建二叉樹 "); printf("\n\t\t 2---------先序遍歷 "); printf("\n\t\t 3---------中序遍歷 "); printf("\n\t\t 4---------后序遍歷 "); printf("\n\t\t 5---------求葉子數(shù) "); printf("\n\t\t 6---------求結(jié)點(diǎn)數(shù) "); printf("\n\t\t 7---------求樹深度 "); printf("\n\t\t 0---------返 回 "); printf("\n\t\t*****************************************"); printf("\n\t\t 請(qǐng)選擇菜單號(hào) (0--7)"); scanf("%c",&ch2); getchar(); printf("\n"); switch(ch2) { case'1': printf("\n\t\t請(qǐng)按先序序列輸入二叉樹的結(jié)點(diǎn):\n"); printf("\n\t\t說明:輸入結(jié)點(diǎn)(‘0’代表后繼結(jié)點(diǎn)為空)后按回車。\n"); printf("\n\t\t請(qǐng)輸入根結(jié)點(diǎn):"); T=CreateTree(); printf("\n\t\t二叉樹成功建立!\n");break; case'2': printf("\n\t\t該二叉樹的先序遍歷序列為:"); Preorder(T);break; case'3': printf("\n\t\t該二叉樹的中序遍歷序列為:"); Inorder(T);break; case'4': printf("\n\t\t該二叉樹的后序遍歷序列為:"); Postorder(T);break; case'5': count=0;Leafnum(T); printf("\n\t\t該二叉樹有%d個(gè)葉子。\n",count);break; case'6': count=0;Nodenum(T); printf("\n\t\t該二叉樹總共有%d個(gè)結(jié)點(diǎn)。\n",count);break; case'7': printf("\n\t\t該樹的深度為:%d",TreeDepth(T)); break; case'0': ch1='n';break; default: printf("\n\t\t***請(qǐng)注意:輸入有誤!***"); } if(ch2!='0') { printf("\n\n\t\t按【Enter】鍵繼續(xù),按任意鍵返回主菜單!\n"); a=getchar(); if(a!='\xA') { getchar(); ch1='n'; } } } } BT *CreateTree() { BT *t; char x; scanf("%c",&x); getchar(); if(x=='0') t=NULL; else { t=new BT; t->data=x; printf("\n\t\t請(qǐng)輸入%c結(jié)點(diǎn)的左子結(jié)點(diǎn):",t->data); t->lchild=CreateTree(); printf("\n\t\t請(qǐng)輸入%c結(jié)點(diǎn)的右子結(jié)點(diǎn):",t->data); t->rchild=CreateTree(); } return t; } void Preorder(BT *T) { if(T) { printf("%3c",T->data); Preorder(T->lchild); Preorder(T->rchild); } } void Inorder(BT *T) { if(T) { Inorder(T->lchild); printf("%3c",T->data); Inorder(T->rchild); } } void Postorder(BT *T) { if(T) { Postorder(T->lchild); Postorder(T->rchild); printf("%3c",T->data); } } void Leafnum(BT *T) { if(T) { if(T->lchild==NULL&&T->rchild==NULL) count++; Leafnum(T->lchild); Leafnum(T->rchild); } } void Nodenum(BT *T) { if(T) { count++; Nodenum(T->lchild); Nodenum(T->rchild); } } int TreeDepth(BT *T) { int ldep,rdep; if(T==NULL) return 0; else { ldep=TreeDepth(T->lchild); rdep=TreeDepth(T->rchild); if(ldep>rdep) return ldep+1; else return rdep+1; } }
上傳時(shí)間: 2020-06-11
上傳用戶:ccccy
數(shù)字基帶傳輸系統(tǒng)的MATLAB仿真實(shí)現(xiàn) function [sampl,re_sampl]=system_1(A,F,P,D,snr,m,N) 輸入變量A ,F,P分別為輸入信號(hào)的幅度、頻率和相位,D為量化電平數(shù),snr 為信道信噪比,N為D/A轉(zhuǎn)換時(shí)的內(nèi)插點(diǎn)數(shù);輸出變量sampl為抽樣后的輸入 信號(hào),re_sampl為恢復(fù)出的輸入信號(hào)。 數(shù)字基帶傳輸系統(tǒng)的MATLAB仿真實(shí)現(xiàn) [sampl,quant,pcm]=a_d_1(A,F,P,D) [changed_ami]=signal_encod_1(pcm) [ami_after_channel]=channel_1(changed_ami,snr) [adjudged_ami]=adjudg_1(ami_after_channel,m) re_pcm=signal_decod_1(adjudged_ami) [re_voltag,re_sampl,re_sampl1]=d_a_1(re_pcm,sampl,D,N)
標(biāo)簽: function re_sampl MATLAB system
上傳時(shí)間: 2017-04-21
上傳用戶:tzl1975
Wi n d o w s使應(yīng)用程序能通過操作系統(tǒng)內(nèi)建的文件系統(tǒng)服務(wù)在網(wǎng)絡(luò)上通信。有時(shí)候,我們 將之稱為“網(wǎng)絡(luò)操作系統(tǒng)”(N O S)能力。
標(biāo)簽: Wi 應(yīng)用程序 操作系統(tǒng) 文件系統(tǒng)
上傳時(shí)間: 2013-12-01
上傳用戶:6546544
本章重點(diǎn)是如何在Wi n d o w s套接字應(yīng)用程序中對(duì)I / O(輸入/輸出)操作進(jìn)行管理。 Wi n s o c k分別提供了“套接字模式”和“套接字I / O模型”,可對(duì)一個(gè)套接字上的I / O行為加以 控制
標(biāo)簽: 套接 Wi 分 應(yīng)用程序
上傳時(shí)間: 2013-12-14
上傳用戶:Shaikh
Winsock 2服務(wù)提供者接口( Service Provider Interface, SPI)代表著另一端的Wi n s o c k編 程(和Winsock 2API相對(duì)應(yīng))。Wi n s o c k的一端是A P I,另一端則是S P I。
標(biāo)簽: Winsock Interface Provider Service
上傳時(shí)間: 2015-07-08
上傳用戶:yoleeson
2的16次冪正整數(shù)d與n,編寫計(jì)算d-1 (mod n) 的程序; 2、對(duì)于三個(gè)不超過2的16次冪正整數(shù)a、e與n,編寫計(jì)算ae (mod n) 的程序。 在上述程序基礎(chǔ)上寫出下列程序: (1) 對(duì)給定的10000以內(nèi)數(shù)判定其是否為素?cái)?shù); (2) 進(jìn)行ElGamal體制的加密與簽名。
上傳時(shí)間: 2013-12-25
上傳用戶:stvnash
四柱漢諾塔問題的求解程序.解題思路:如a,b,c,d四柱. 要把a(bǔ)柱第n個(gè)盤移到目標(biāo)柱子(d柱),先把上層 分兩為兩部份,上半部份移到b柱,下半部分移到c柱,再把第n盤移到 目標(biāo)柱子,然后,c柱盤子再移到目標(biāo)柱子,再把b柱盤子移到目標(biāo)柱子. 細(xì)節(jié)地方: 上半部份移到b柱時(shí),它的中間變量柱子是有二選一的.而下半部分 移到c柱時(shí),它的中間變量柱子只有一個(gè)(因?yàn)橐粋€(gè)柱子已被上半部份 占了).b,c也移到目標(biāo)柱子時(shí)同理。
上傳時(shí)間: 2013-12-22
上傳用戶:aeiouetla
鄰接矩陣類的根是A d j a c e n c y W D i g r a p h,因此從這個(gè)類開始。程序1 2 - 1給出了類的描述。程 序中,先用程序1 - 1 3中函數(shù)Make2DArray 為二組數(shù)組a 分配空間,然后對(duì)數(shù)組a 初始化,以描述 一個(gè)n 頂點(diǎn)、沒有邊的圖的鄰接矩陣,其復(fù)雜性為( n2 )。該代碼沒有捕獲可能由M a k e 2 D A r r a y 引發(fā)的異常。在析構(gòu)函數(shù)中調(diào)用了程序1 - 1 4中的二維數(shù)組釋放函數(shù)D e l e t e 2 D
標(biāo)簽: 矩陣
上傳時(shí)間: 2013-12-21
上傳用戶:lanjisu111
一個(gè)旅行家想駕駛汽車從城市A到城市B(設(shè)出發(fā)時(shí)油箱是空的)。給定兩個(gè)城市之間的距離dis、汽車油箱的容量c、每升汽油能行駛的距離d、沿途油站數(shù)n、油站i離出發(fā)點(diǎn)的距離d[i]以及該站每升汽油的價(jià)格p[i],i=1,2,…,n。設(shè)d[1]=0<d[2]<…<d[n]。要花最少的油費(fèi)從城市A到城市B,在每個(gè)加油站應(yīng)加多少油,最少花費(fèi)為多少?
上傳時(shí)間: 2013-12-31
上傳用戶:redmoons
Flash掃雷游戲源碼: 按住S后點(diǎn)鼠標(biāo)左鍵掃雷 按住D后點(diǎn)鼠標(biāo)右鍵標(biāo)記雷 可以輸入縱橫長度決定難度
標(biāo)簽: Flash 鼠標(biāo) 源碼 標(biāo)記
上傳時(shí)間: 2013-12-22
上傳用戶:ayfeixiao
蟲蟲下載站版權(quán)所有 京ICP備2021023401號(hào)-1