递归建树


TreeNode* Build(int & p,string str){
    char c=str[p++];
    if(c=='#'){
        return NULL;
    }
    TreeNode* root=new TreeNode(c);
    root->leftchild=Build(p,str);
    root->rightchild=Build(p,str);
    return root;
}

全部评论
注意是int & p;为了防止递归回溯时p变回了原来的数值,p要一直增加。
点赞 回复 分享
发布于 2022-10-11 21:48 福建
先序
点赞 回复 分享
发布于 2022-10-11 11:35 福建

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务