층계 생성 두 갈래 나무

4820 단어 나무.
#define NoInfo 0/* NoInfo, */

BinTree CreateBinTree()
{
    int data;
    BinTree BT, T;

    Queue Q = CreatQueue();
    scanf("%d", &data);
    if(data != NoInfo){
        BT = (BinTree)malloc(sizeof(struct TNode));
        BT->data = data;
        BT->left = BT->right = NULL;
        Add(Q, BT);
    }else{
        return NULL;
    }

    while(!IsEmpty(Q)){
        T = Delete(Q);// , 

        scanf("%d", &data);// T 
        if(data == NoInfo){// 
            T->left = NULL;
        }else{
            T->left = (BinTree)malloc(sizeof(struct TNode));
            T->left->data = data;
            T->left->left = T->left->right = NULL;
            Add(Q, T->left);
        }

        scanf("%d", &data);// T 
        if(data == NoInfo){
            T->right = NULL;
        }else{
            T->right = (BinTree)malloc(sizeof(struct TNode));
            T->right->data = data;
            T->right->left = T->right->right = NULL;
            Add(Q, T->right);
        }
    }
    return BT;
}

좋은 웹페이지 즐겨찾기