二叉樹の各層のノード数の最大値とこのツリーの高さの積を求めます.
8283 ワード
高さツリーは再帰的に使用され、接合点数の最大値を求めるためのキューを使用します.
int Depth(BTree T){
if (T == Null){//
return 0;
}else{
int ldepth = Depth(T -> lchild);//
int rdepth = Depth(T -> rchild);
}
if (ldepth > rdepth){
return ldepth + 1;//
}else{
return rdepth + 1;//
}
}
int LayerMaxNodes(BTree T){
BTree QUEUE[MAXSIZE], P;
int MaxNumberLevel = 1, NxetLevelNumber ;/
int front = -1, rear = 0, last = 0, curlevel = 1;
if (T = NULL) return 0;
QUEUE[rear] = T;
while (front < rear){//
p = QUEUE[++front];
if (p ->lchild != NULL){
QUEUE[++rear] = p ->lchild;
NextLevelNumber++;
}
if (p ->rlchild != NULL){
QUEUE[++rear] = p ->rchild;
NextLevelNumber++;
}
if (front == last){// front , , last rear
if ( MaxNumberLevel < NextLevelNumber){
MaxNumberLevel = NextLevelNumber;//
NextLevelNumber = 0;// 0
}
curlevel++;
last = rear;
}
}
return MaxNumberLevel;
}
int DegreeOfLush(BTree T){
int lush;
lush = Depth(BTree T) * LayerMaxNodes(BTree T);
return lush;
}//