文章

10

粉丝

0

获赞

5

访问

756

头像
二叉树遍历 题解:
P1161 清华大学/南京大学2018机试题
发布于2025年2月20日 13:10
阅读数 75

#include<iostream>
#include<string>

struct TreeNode {
    char ch;
    TreeNode* lchild;
    TreeNode* rchild;
};
std::string s = "";
int length = 0;
void CreateTree(TreeNode*& root) {
    if (length==s.size())
    {
        return;
    }
    char ch = s[length++];
    if (ch == '#')
    {
        root = nullptr;
    }
    else {
        root = new TreeNode();
        root->ch = ch;
        root->lchild = nullptr;
        root->rchild = nullptr;
        CreateTree(root->lchild);
        CreateTree(root->rchild)...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发