```
class Solution {
public:
void connect(TreeLinkNode *root) {
while (root) {
TreeLinkNode *a = root;
while (a) {
if (a->left) {
a->left->next = a->right;
if (a->next)
a->right->next = a->next->left;
}
a=a->next;
}
root=root->left;
}
}
};
```