C++ || BFS || Iterative || queue
\n/*\n// Definition for a Node.\nclass Node {\npublic:\n    int val;\n    Node* left;\n    Node* right;\n    Node* next;\n\n    Node() : val(0), left(NULL), rig
```\n/*\n// Definition for a Node.\nclass Node {\npublic:\n    int val;\n    Node* left;\n    Node* right;\n    Node* next;\n\n    Node() : val(0), left(NULL), right(NULL), next(NULL) {}\n\n    Node(int _val) : val(_val), left(NULL), right(NULL), next(NULL) {}\n\n    Node(int _val, Node* _left, Node* _right, Node* _next)\n        : val(_val), left(_left), right(_right), next(_next) {}\n};\n*/\n\nclass Solution {\npublic:\n    Node* connect(Node* root) {\n        if(!root)return root;\n        queue<Node*> q;\n        q.push(root);\n        while(!q.empty()){\n            int n=q.size();\n            for(int i=0;i<n;i++){\n                Node* x=q.front();\n                q.pop();\n                if(i!=n-1)x->next=q.front();\n                if(x->left)q.push(x->left);\n                if(x->right)q.push(x->right);\n            }\n        }\n        return root;\n    }\n};\n```
['Breadth-First Search', 'Queue', 'C', 'C++']