> 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.md).

# Populating Next Right Pointers in Each Node

void connect(TreeLinkNode \*root) {

connect(root,NULL);

}

void connect(TreeLinkNode *root, TreeLinkNode* sub){

if(!root) return;

root->next=sub;

connect(root->left,root->right);

if(sub)

connect(root->right,sub->left);

else

connect(root->right,NULL);

}

};
