美文网首页
116 populating next right pointe

116 populating next right pointe

作者: larrymusk | 来源:发表于2017-12-05 11:05 被阅读0次
void dfs(struct TreeLinkNode *parent){
    if(parent->left == NULL || parent->right == NULL)
        return;
    parent->left->next = parent->right;
    if(parent->next != NULL)
        parent->right->next = parent->next->left;
    else
        parent->right->next = NULL;

    dfs(parent->left);
    dfs(parent->right);
}
void connect(struct TreeLinkNode *root) {
if(root == NULL)
    return;
root->next = NULL;//1th
dfs(root);
}

相关文章

网友评论

      本文标题:116 populating next right pointe

      本文链接:https://www.haomeiwen.com/subject/sqvqixtx.html