C++ BFS and DFS
BFS\n\ncpp\nclass Solution {\npublic:\n    vector<vector<int>> levelOrder(TreeNode* root) {\n        if (!root) {\n            return {};\n        }\n        ve
**BFS**\n\n```cpp\nclass Solution {\npublic:\n    vector<vector<int>> levelOrder(TreeNode* root) {\n        if (!root) {\n            return {};\n        }\n        vector<vector<int>> levels;\n        queue<TreeNode*> todo;\n        todo.push(root);\n        while (!todo.empty()) {\n            levels.push_back({});\n            for (int i = 0, n = todo.size(); i < n; i++) {\n                TreeNode* node = todo.front();\n                todo.pop();\n                levels.back().push_back(node -> val);\n                if (node -> left) {\n                    todo.push(node -> left);\n                }\n                if (node -> right) {\n                    todo.push(node -> right);\n                }\n            }\n        }\n        return levels;\n    }\n};\n```\n\n**DFS**\n\n```cpp\nclass Solution {\npublic:\n    vector<vector<int>> levelOrder(TreeNode* root) {\n        if (!root) {\n            return {};\n        }\n        vector<vector<int>> levels;\n        level(root, 0, levels);\n        return levels;\n    }\nprivate:\n    void level(TreeNode* root, int l, vector<vector<int>>& levels) {\n        if (!root) {\n            return;\n        }\n        if (levels.size() <= l) {\n            levels.push_back({});\n        }\n        levels[l].push_back(root -> val);\n        level(root -> left, l + 1, levels);\n        level(root -> right, l + 1, levels);\n    }\n};\n```
['Binary Tree', 'C++']