diff --git a/.codespellrc b/.codespellrc new file mode 100644 index 0000000..74bed49 --- /dev/null +++ b/.codespellrc @@ -0,0 +1,4 @@ +[codespell] +ignore_words = "ans" +count = +quiet-level = 3 diff --git a/Data-Structures/Trees/07-level-order.md b/Data-Structures/Trees/07-level-order.md index c9638f1..508b7de 100644 --- a/Data-Structures/Trees/07-level-order.md +++ b/Data-Structures/Trees/07-level-order.md @@ -1,6 +1,6 @@ ## Level Order Traversal [BFS] C++ Implementation -==> We'll need two data structures, A queue and a vector of vectors. +==> We'll need two data sructures, A queue and a vector of vectors. --> The Queue will hold the roots of tree. @@ -94,8 +94,8 @@ The vector becomes : ### Approach : -- Declare a vector of vectors (and). -- if root == NULL, return and. +- Declare a vector of vectors (ans). +- if root == NULL, return ans. - declare a queue, push the root into it. - while the queue is not empty, - calculate it's size to traverse. @@ -105,14 +105,14 @@ The vector becomes : - pop the node out of the queue and check if it's left and right exists. - If exists, push them to queue - push the node's value into the (level) vector. -- push the (level) vector to (and) vector. +- push the (level) vector to (ans) vector. --- ### Implementation : ```cpp -/* Definition for binary tree : +/* Defination for binary tree : struct TreeNode { int val; TreeNode *left; @@ -127,9 +127,9 @@ right(right) {} class Solution { public: vector> levelOrder(TreeNode* root) { - vector>and; // vector of vector + vector> ans; // vector of vector if (root == NULL) - return and; + return ans; queue q; // queue q.push(root); while (!q.empty()) { @@ -144,9 +144,9 @@ class Solution { q.push(node->right); level.push_back(node->value); } - and.push_back(level); + ans.push_back(level); } - return and; + return ans; } }; ``` diff --git a/Data-Structures/Trees/08-in-order-iterative.md b/Data-Structures/Trees/08-in-order-iterative.md index 10b4567..6abab3a 100644 --- a/Data-Structures/Trees/08-in-order-iterative.md +++ b/Data-Structures/Trees/08-in-order-iterative.md @@ -1,6 +1,6 @@ ## In order traversal ~ Iterative Approach ---> In this approach, we'll need an auxiliary stack space and the stack will hold the upcoming nodes. +--> In this approach, we'll need an auxillary stack space and the stack will hold the upcoming nodes. **Approach :** @@ -73,7 +73,7 @@ Stack becomes : ### Implementation : ```cpp -/* Definition for binary tree : +/* Defination for binary tree : struct TreeNode { int val; TreeNode *left; @@ -90,7 +90,7 @@ class Solution { vector inorderTraversal(TreeNode* root) { stack st; // declare a stack - vectorand; // declare an answer vector + vector ans; // declare an answer vector TreeNode* node = root; // take the root node @@ -103,11 +103,11 @@ class Solution { break; node = st.top(); // if null, st.pop(); // pop the node out - and.push_back(node->val); // push it to and vector + ans.push_back(node->val); // push it to ans vector node = node->right; // now check for right } } - return and; + return ans; } }; ``` diff --git a/Data-Structures/Trees/09-pre-order-iterative.md b/Data-Structures/Trees/09-pre-order-iterative.md index f4bc8cd..fe629c5 100644 --- a/Data-Structures/Trees/09-pre-order-iterative.md +++ b/Data-Structures/Trees/09-pre-order-iterative.md @@ -6,14 +6,14 @@ 2. Start the Stack iteration, pop the top most element out and push it to the answer vector, then check if it has any left or right. 3. If left or right not NULL, first push right then left into the stack. 4. The stack iteration continues, pop the top most (left) element out and push it to the answer vector, then check if it has any left or right. -5. Continue the iteration until the stak gets empty. +5. Continue the iteration untill the stak gets empty. ![pre-order-itr](https://github.com/Rishabh672003/Programming-Notes/assets/53911515/eb403e15-29ca-410a-913b-b9f79822c59a) ### Implementation : ```cpp -/* Definition for binary tree : +/* Defination for binary tree : struct TreeNode { int val; TreeNode *left; @@ -29,9 +29,9 @@ class Solution { public: vector preorder(TreeNode* root) { - vectroand; + vectro ans; if (root == NULL) - return and; + return ans; stack st; st.push(root); @@ -40,7 +40,7 @@ class Solution { root = st.top(); st.pop(); - and.push_back(root->val); + ans.push_back(root->val); if (root->right != NULL) { st.push(root->right); @@ -49,7 +49,7 @@ class Solution { st.push(root->left); } } - return and; + return ans; } }; ``` diff --git a/Data-Structures/Trees/10-post-order-twoStack.md b/Data-Structures/Trees/10-post-order-twoStack.md index f50c939..d30b55a 100644 --- a/Data-Structures/Trees/10-post-order-twoStack.md +++ b/Data-Structures/Trees/10-post-order-twoStack.md @@ -33,7 +33,7 @@ class Solution { public: vector postOrderTwoStack(TreeNode* root) { - vectorand; + vector ans; if (root == NULL) return and; @@ -55,11 +55,11 @@ class Solution { } while (!st2.empty()) { - and.push_back(st2.top()->val); + ans.push_back(st2.top()->val); st2.pop(); } - return and; + return ans; } } ``` diff --git a/Data-Structures/Trees/11-post-order-oneStack.md b/Data-Structures/Trees/11-post-order-oneStack.md index 0cf36cf..b26c651 100644 --- a/Data-Structures/Trees/11-post-order-oneStack.md +++ b/Data-Structures/Trees/11-post-order-oneStack.md @@ -1,7 +1,7 @@ ## Post Order Traversal ~ One Stack Iteration ```cpp -/* Definition for binary tree : +/* Defination for binary tree : struct TreeNode { int val; TreeNode *left; @@ -16,9 +16,9 @@ right(right) {} class Solution { public: vector postOrderOneStack(TreeNode* root) { - vectorand; + vector ans; if (root == NULL) - return and; + return ans; TreeNode* curr = root; TreeNode* temp = NULL; @@ -33,11 +33,11 @@ class Solution { if (temp == NULL) { temp = st.top(); st.pop(); - and.push_back(temp); + ans.push_back(temp); while (!st.empty()&& temp = st.top()->right) { temp = st.top(); st.pop(); - and.push_back(temp); + ans.push_back(temp); } } else { curr = temp; diff --git a/Data-Structures/Trees/problems/count-leaves.cpp b/Data-Structures/Trees/problems/count-leaves.cpp index 3ecd300..11db24c 100644 --- a/Data-Structures/Trees/problems/count-leaves.cpp +++ b/Data-Structures/Trees/problems/count-leaves.cpp @@ -5,7 +5,7 @@ struct TreeNode { int val; TreeNode* left; TreeNode* right; - TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + explicit TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} }; class Solution {