Thanks for liji94188 for adding the explanation:

It's a BFS traversal. now pointer is the current level traveler and head is the left most element at next level and the tail is the right most element at next level till now. We move now pointer at current level and populate the the next-link at its children level. (Here the gist is we can move now to its next because this relationship was already populated in the previous round).

```
void connect(TreeLinkNode *root) {
TreeLinkNode *now, *tail, *head;
now = root;
head = tail = NULL;
while(now)
{
if (now->left)
if (tail) tail = tail->next =now->left;
else head = tail = now->left;
if (now->right)
if (tail) tail = tail->next =now->right;
else head = tail = now->right;
if(!(now = now->next))
{
now = head;
head = tail=NULL;
}
}
}
```