[recommend for beginners]clean C++ implementation with detailed explanation
class Solution {\n    public:\n        vector<vector<int>> zigzagLevelOrder(TreeNode* root) {\n            vector<vector<int>> result;\n            if(!root) re
    class Solution {\n    public:\n        vector<vector<int>> zigzagLevelOrder(TreeNode* root) {\n            vector<vector<int>> result;\n            if(!root) return result;\n            deque<TreeNode*> tree;\n            tree.push_back(root);\n            int flag=0;\n            while(!tree.empty()){\n                int count=tree.size();\n                vector<int> level;\n                while(count-- > 0){\n                    TreeNode* cur=tree.front();\n                    tree.pop_front();\n                    level.push_back(cur->val);\n                    if(cur->left) tree.push_back(cur->left);\n                    if(cur->right) tree.push_back(cur->right);\n                }\n                if(flag & 1) reverse(level.begin(), level.end());\n                result.push_back(level);\n                flag++;\n            }\n            return result;\n        }\n    };
[]