在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/人工智能  C/ 用先序遞歸建樹,函數(shù)無法退出

用先序遞歸建樹,函數(shù)無法退出

// Tree struct
typedef struct tree
{
    ElemType data;
    struct tree * lchild;
    struct tree * rchild;
}TreeNode,* Tree;

void CreateTree(Tree* t)
{
    char ch;
    scanf("%c",&ch);
    if ( ch == '#' ){
        *t = NULL;
    }
    else
    {
        *t = (Tree)malloc(sizeof(TreeNode));
        if ( !(*t) )
        {
            printf("memory allocate error!");
            return ;
        }
        (*t)->data = ch;
        CreateTree(&((*t)->lchild));
        CreateTree(&((*t)->rchild));
    }
    return ;
}
int main()
{
    Tree T;
    printf("\nPlease input node in preorder way,'#'means NULL:");
    CreateTree(T);
}

程序執(zhí)行到CreateTree里面無法退出,遞歸退出判斷條件如何寫?

回答
編輯回答
傻丟丟

終端輸入2次 # 回車

2018年5月26日 21:25