Video solution | Actual zig zag traversal | Complete intuition in detail | C++
Video\nHey everyone i have created a video solution for this problem where we will actually traverse the binary tree in zig zag order , in the video i will be t
# Video\nHey everyone i have created a video solution for this problem where we will actually traverse the binary tree in zig zag order , in the video i will be taking you through the complete thought process and intuition for the video, do watch till the end for complete explanantion.\n\nVideo link: https://youtu.be/1fhszgcls5w\nPlaylist link: https://www.youtube.com/playlist?list=PLICVjZ3X1Aca0TjUTcsD7mobU001CE7GL \n\n\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 */\nclass Solution {\npublic:\n    vector<vector<int>> zigzagLevelOrder(TreeNode* root) {\n    vector<vector<int>> res;\n    if(!root) return res;\n    deque<TreeNode*> dq;\n    int level=0;\n    dq.push_back(root);\n    while(!dq.empty()){\n        int l=dq.size();\n        vector<int> temp;\n        for(int i=0;i<l;i++){\n            if(level%2==0){\n                TreeNode* node= dq.back();\n                dq.pop_back();\n                temp.push_back(node->val);\n                if(node->left) dq.push_front(node->left);\n                if(node->right) dq.push_front(node->right);\n\n            }\n            else{\n                TreeNode* node= dq.front();\n                dq.pop_front();\n                temp.push_back(node->val);\n                if(node->right) dq.push_back(node->right);\n                if(node->left) dq.push_back(node->left);\n\n            }\n        }\n        level++;\n        res.push_back(temp);\n    }\n\n    \n\n    return res;\n    }\n};\n```
['C++']