BFS | Iterative | Video Solution | Must Watch for intuition
Video\nHey everyone, i have created a video solution for iterative version , and have explained intuition in very detail and from that intutition i have done th
# Video\nHey everyone, i have created a video solution for iterative version , and have explained intuition in very detail and from that intutition i have done the implementation, it\'s a very important video, as its a basic building block of trees and graphs.\n\nIterative: \nhttps://youtu.be/1tVrdVA4Wz0\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\n\n/* Iterative */\nclass Solution {\npublic:\n    vector<vector<int>> output;\n\n    vector<vector<int>> levelOrder(TreeNode* root) {\n        queue<TreeNode*> q;\n        if(root){\n            q.push(root);\n        }\n        while(!q.empty()){\n            int l=q.size();\n            vector<int> temp;\n            for(int i=0;i<l;i++){\n                TreeNode* t=q.front();\n                if(t->left) q.push(t->left);\n                if(t->right) q.push(t->right);\n                temp.push_back(t->val);\n                q.pop();\n\n            }\n            output.push_back(temp);\n        }\n\n        return output;\n    }\n\n   \n};\n\n\n\n\n```
['C++']