succinct and maybe more efficient solution 

    void connectQueue(TreeLinkNode *root) {
        if (!root) return;
        
        queue<TreeLinkNode *> q;
        q.push(root);
        while (!q.empty()) {
            TreeLinkNode *prev = nullptr, *curr = nullptr;
            int n = q.size();
            for (int i = 0; i < n; ++i) {
                curr = q.front(); q.pop();
                if (prev) prev->next = curr;
                prev = curr;
                
                if (curr->left) q.push(curr->left);
                if (curr->right) q.push(curr->right);
            }
        }
    }