```
void connect(TreeLinkNode *root) {
if(!root || !root->left || !root->right)
return;
root->left->next = root->right;
if(root->next)
root->right->next = root->next->left;
else
root->right->next = NULL;
connect(root->left);
connect(root->right);
}
```