可能編譯時會有些語法小錯誤(比如分號,->,等),很容易就自己糾正了哦,思路絕對是完全正確的,所以用的話就自己試著改改吧,直接復制粘貼,就正確,豈不是太沒寫代碼體驗了,自己改改才印象更加深刻的呢(▽)~~~~;
#include<iostream>
using namespace std;
typedef struct BiNode{
char data;
struct BiNode *lchild,*rchild;
}BiTNode,*BiTree;
void CreateBiTree(BiTree &T){
char ch;
cin >> ch;
if(ch=='#') T=NULL;
else{
T=new BiTNode;
T->data=https://www.cnblogs.com/ygjzs/p/ch;
CreateBiTree(T->lchild);
CreateBiTree(T->rchild);
}
}
int Depth(BiTree T){
int m,n;
if(T==NULL) retue 0;
else{
m=Depth(T->lchild);
n=Depth(T->rchild);
if(m>n) return(m+1);
else{
return (n+1);
}
}
}
void main(){
BiTree tree;
cout<<"please input:\n";
CreateBiTree(tree);
cout<<"deepth is:"<<Depth(tree)<<endl;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/125578.html
標籤:其他
上一篇:建立二叉樹
下一篇:求節點數
