算法
int BTDepth(BiNode *T){
if(!T) return 0;
int front = -1, rear = -1;
int last = 0;
int most = 1;
BiNode* Queue[maxsize];
Queue[++rear] = T;
BiNode *temp;
while(front != rear){
temp = Queue[++front];
if(temp->lchild){
Queue[++rear] = temp->lchild;
}
if(temp->rchild){
Queue[++rear] = temp->rchild;
}
if(front == last){
if(most
测试环境
#include
#include
#include
#define maxsize 100
//二叉树的创建序列
//ab#df###c#e##
//abd##e##cf###
//abce##f##dg##h###
typedef struct BiNode{
char date;
struct BiNode *lchild,*rchild;
}BiNode;
BiNode* CreateBiTree();
int BTDepth(BiNode *T);
int main(){
BiNode* t = CreateBiTree();
int most = BTDepth(t);
printf("%d",most);
return 0;
}
int BTDepth(BiNode *T){
if(!T) return 0;
int front = -1, rear = -1;
int last = 0;
int most = 1;
BiNode* Queue[maxsize];
Queue[++rear] = T;
BiNode *temp;
while(front != rear){
temp = Queue[++front];
if(temp->lchild){
Queue[++rear] = temp->lchild;
}
if(temp->rchild){
Queue[++rear] = temp->rchild;
}
if(front == last){
if(mostdate=a;
p->lchild=CreateBiTree();
p->rchild=CreateBiTree();
}
return p;
}
//递归方法中序遍历二叉树
void Traverse(BiNode *p){
if(p==NULL){
return;
}
else{
Traverse(p->lchild);
printf("%c",p->date);
Traverse(p->rchild);
}
return;
}