```
void connectMiddle(TreeLinkNode *rootLeft, TreeLinkNode *rootRight)
{
if (rootLeft->right && rootRight->left)
rootLeft->right->next = rootRight->left;
}
void connect(TreeLinkNode *root)
{
TreeLinkNode *tmp = root;
if (root && root->left && root->right)
{
root->left->next = root->right;
connect(root->left);
connect(root->right);
tmp = root->left;
while (tmp->next)
{
connectMiddle(tmp, tmp->next);
tmp = tmp->next;
}
}
}
```

I am assuming the tree is perfect as noted... but it seems like the serialization didn't convince me that it is a perfect tree. Please let me know where I got it wrong. Thanks!