```
void connect(TreeLinkNode *root) {
connectNext(root);
}
void connectNext(TreeLinkNode *node)
{
if (!node) return;
if (node->left && node->right)
node->left->next = node->right; // assign next of left as right
if (node->next && node->right)
node->right->next = node->next->left; // assign next pointer of right as left of its parent's next
connectNext(node->left);
connectNext(node->right);
}
```