Bootstrap

PTA:数据结构与算法题目集(中文)

求二叉树深度:

int GetHeight( BinTree BT ){
    while(BT){
        if(BT->Left==NULL&&BT->Right==NULL){
            return 1;
        }
        else if(BT->Left==NULL&&BT->Right!=NULL){
            return GetHeight(BT->Right)+1;
        }
        else if(BT->Left!=NULL&&BT->Right==NULL){
            return GetHeight(BT->Left)+1;
        }
        else{
            return (GetHeight(BT->Left)>GetHeight(BT->Right)?GetHeight(BT->Left):GetHeight(BT->Right))+1;
        }
    }
}

 

;