Recursive

void connect(TreeLinkNode *root) {

if(!root) return;

TreeLinkNode dummy(-1), *p;

for(p=&dummy;root;root=root->next){

if(root->left){

p->next=root->left;

p=p->next;

}

if(root->right){

p->next=root->right;

p=p->next;

}

}

connect(dummy.next);

}

Last updated

Was this helpful?