> For the complete documentation index, see [llms.txt](https://nataliekung.gitbook.io/solutions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nataliekung.gitbook.io/solutions/populating_next_right_pointers_in_each_node_ii/recursive.md).

# 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);

}
