116 populating next right pointe

2017-12-05  本文已影响0人  larrymusk
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);
}
上一篇 下一篇

猜你喜欢

热点阅读