文章

2

粉丝

326

获赞

0

访问

21.9k

头像
重建二叉树成功,为啥还是通过0?
P1161 清华大学/南京大学2018机试题
发布于2019年12月22日 14:57
阅读数 10.2k

#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct ListNode{
    char val;
    ListNode* left;
    ListNode* right;
    ListNode(char ch) : val(ch), left(NULL), right(NULL){}
};

void makeTree(string str, int& pos, ListNode* root)
{
    if (pos >= str.size() || !root)
    {
        return;
    }
    if (str[++pos] != '#')
        root->left = new ListNode(str[pos]);
    makeTree(str, pos, root->left);
    if (str[++pos] != '#')
        root->right = new ListNode(str[pos]);
    makeTree(str, pos, root->right);
}

void MidTraverse(ListNode* root, string& str)
{
    if (root == NULL)
        return...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发