diff --git a/Templates/functions.md b/Templates/functions.md index aa76509..29884a5 100644 --- a/Templates/functions.md +++ b/Templates/functions.md @@ -344,36 +344,7 @@ void mergesort(ListNode*& A) } ``` -### Binary Tree Level Order Traversal - -``` -vector> levelOrder(TreeNode* root) -{ - if(root==NULL) return{}; - vector> v; - queue q; - q.push(root); - - TreeNode *tempNode=root; - while(!q.empty()) - { - int n = q.size(); - vector ans(n); - for(int i=0;ival; - // cout<left) q.push(tempNode->left); - if(tempNode->right) q.push(tempNode->right); - q.pop(); - tempNode=q.front(); - } - v.push_back(ans); - } - return v; -} -``` # Max Depth of Binary Tree using top-down approach @@ -501,3 +472,34 @@ void heapify(int arr[], int n, int i) } } ``` + +### Binary Tree Level Order Traversal + +``` +vector> levelOrder(TreeNode* root) +{ + if(root==NULL) return{}; + vector> v; + queue q; + q.push(root); + + TreeNode *tempNode=root; + while(!q.empty()) + { + int n = q.size(); + vector ans(n); + for(int i=0;ival; + // cout<left) q.push(tempNode->left); + if(tempNode->right) q.push(tempNode->right); + q.pop(); + tempNode=q.front(); + } + v.push_back(ans); + + } + return v; +} +``` \ No newline at end of file