diff --git a/data_structures/binary_tree/cpp/BurningTree.cpp b/data_structures/binary_tree/cpp/BurningTree.cpp new file mode 100644 index 00000000..7410eef0 --- /dev/null +++ b/data_structures/binary_tree/cpp/BurningTree.cpp @@ -0,0 +1,61 @@ +/** + * Definition for a binary tree node. + * struct TreeNode { + * int val; + * TreeNode *left; + * TreeNode *right; + * TreeNode() : val(0), left(nullptr), right(nullptr) {} + * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} + * }; + */ +class Solution { +public: + vector> verticalOrder(TreeNode *root) + { + //Your code here + queue>>q; + vector>ans; + q.push({root,{0,0}}); + map>>m; + while(!q.empty()){ + + int n=q.size(); + + for(int i=0;ival}); + if(x.first->left!=NULL){ + + q.push({x.first->left,{x.second.first-1,x.second.second+1}}); + + + + } + if(x.first->right!=NULL){ + q.push({x.first->right,{x.second.first+1,x.second.second+1}}); + + } + + } + + } + for(auto i: m){ + vectorv; + for(auto j: i.second){ + + //cout<> verticalTraversal(TreeNode* root) { + return verticalOrder(root); + + } +};