#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 二叉樹子系統"); 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---------求葉子數 "); printf("\n\t\t 6---------求結點數 "); printf("\n\t\t 7---------求樹深度 "); printf("\n\t\t 0---------返 回 "); printf("\n\t\t*****************************************"); printf("\n\t\t 請選擇菜單號 (0--7)"); scanf("%c",&ch2); getchar(); printf("\n"); switch(ch2) { case'1': printf("\n\t\t請按先序序列輸入二叉樹的結點:\n"); printf("\n\t\t說明:輸入結點(‘0’代表后繼結點為空)后按回車。\n"); printf("\n\t\t請輸入根結點:"); 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個葉子。\n",count);break; case'6': count=0;Nodenum(T); printf("\n\t\t該二叉樹總共有%d個結點。\n",count);break; case'7': printf("\n\t\t該樹的深度為:%d",TreeDepth(T)); break; case'0': ch1='n';break; default: printf("\n\t\t***請注意:輸入有誤!***"); } if(ch2!='0') { printf("\n\n\t\t按【Enter】鍵繼續,按任意鍵返回主菜單!\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請輸入%c結點的左子結點:",t->data); t->lchild=CreateTree(); printf("\n\t\t請輸入%c結點的右子結點:",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; } }
上傳時間: 2020-06-11
上傳用戶:ccccy
Service Pack 一手搞定.mht Windows 瘦身.mht 創建可引導光盤更完美.mht 裝Win Me-2000免輸序列號.htm
上傳時間: 2015-01-13
上傳用戶:黃華強
題目:參加運動會的N個學校編號為1~N.比賽分成M個男子項目和W個女子項目,項目編號分別為1~M和M+1~M+W.由于個項目參加人數差別較大,有些項目取前5名,得分順序為7,5,3,2,1 還有些項目只取前3名,得分順序為5,3,2.寫一個統計程序產生各種成績單和得分報表.基本要求:產生各學校的成績單,內容包括各校所取得的每項成績的項目號,名次,姓名和得分 產生團體總分報表,內容包括校號,男子團體總分,女子團體總分和團體總分.概要設計:1. 為實現上述程序功能,應以線性表表示集合.2. 本程序包含3個模塊:(1) 各集合定義模塊(2) 線性表實現模塊(3) 主程序模塊
上傳時間: 2013-12-21
上傳用戶:黃華強
slickeditv10.0linuxcrackz.w.t.zip SlickEdit v10.0 for linux 注冊機 在國內網站上找了N天都沒找到,在國外一家網站找到。雖然不是源代碼,但是SlickEdit是Linux下最好用的30多種編程IDE。這個是注冊機安裝文件在百度裡找吧
標簽: 10.0 linuxcrackz slickeditv SlickEdit
上傳時間: 2013-12-10
上傳用戶:大融融rr
Wi n d o w s使應用程序能通過操作系統內建的文件系統服務在網絡上通信。有時候,我們 將之稱為“網絡操作系統”(N O S)能力。
上傳時間: 2013-12-01
上傳用戶:6546544
本章重點是如何在Wi n d o w s套接字應用程序中對I / O(輸入/輸出)操作進行管理。 Wi n s o c k分別提供了“套接字模式”和“套接字I / O模型”,可對一個套接字上的I / O行為加以 控制
上傳時間: 2013-12-14
上傳用戶:Shaikh
c語言。定步長求解龍哥庫塔的方程。可以用n來表示方程組得個數。此方法單精度。
上傳時間: 2015-07-12
上傳用戶:yuzsu
范德蒙行列式求解方法,VANDER(X[],W[],Q[],N),在子過程Vander中實現。
上傳時間: 2015-08-29
上傳用戶:fnhhs
本源程序系`一款多用電子鐘芯片 源程序,可有3開3關定時,且有受雙限觸發的定時口
上傳時間: 2015-09-01
上傳用戶:yt1993410
有向直線K中值問題 給定一條有向直線L以及L 上的n+1 個點x0<x1<x2<… <xn。有向直線L 上的每個點xi都有一個權 w(xi) 每條有向邊 (xi,xi-1),也都有一個非負邊長d(xi,xi-1)。有向直線L 上的每個點xi 可以看作客戶,其服務需求量為w(xi) 。每條邊(xi,xi-1) 的邊長 , d(xi,xi-1) 可以看作運輸費用。如果在點xi 處未設置服務機構,則將點xi 處的服務需求沿有向邊轉移到點xj處服務機構需付出的服務轉移費用為w(xi)*d(xi,xj) 。在點0 x 處已設置了服務機構,現在要在直線L上增設k處服務機構,使得整體服務轉移費用最小。
上傳時間: 2014-01-14
上傳用戶:manlian