```
class Solution {
public:
void connect(TreeLinkNode *root) {
if(root == NULL) return;
if(root->left != NULL) root->left->next = root->right;
if(root->next != NULL && root->right != NULL) root->right->next = root->next->left;
if(root->left != NULL) connect(root->left);
if(root->right != NULL) connect(root->right);
}
};
```