C++ solutions
\nclass Solution {\npublic:\n    Node* connect(Node* root) {\n        queue<Node*> q;\n        if (root) q.push(root);\n        while (q.size()) {\n            
```\nclass Solution {\npublic:\n    Node* connect(Node* root) {\n        queue<Node*> q;\n        if (root) q.push(root);\n        while (q.size()) {\n            int len = q.size();\n            Node* curr;\n            while (len--) {\n                curr = q.front(), q.pop();\n                curr->next = len ? q.front():NULL;\n                if (curr->left) q.push(curr->left);\n                if (curr->right) q.push(curr->right);         \n            }\n        }         \n        return root;\n    }\n};\n\n```
['C', 'C++']