Skip to content

Commit

Permalink
added a codespell config and other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh672003 committed Oct 29, 2023
1 parent f1bac01 commit 8238ae2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 29 deletions.
4 changes: 4 additions & 0 deletions .codespellrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[codespell]
ignore_words = "ans"
count =
quiet-level = 3
18 changes: 9 additions & 9 deletions Data-Structures/Trees/07-level-order.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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.
Expand All @@ -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;
Expand All @@ -127,9 +127,9 @@ right(right) {}
class Solution {
public:
vector<vector<int>> levelOrder(TreeNode* root) {
vector<vector<int>>and; // vector of vector
vector<vector<int>> ans; // vector of vector
if (root == NULL)
return and;
return ans;
queue<TreeNode*> q; // queue
q.push(root);
while (!q.empty()) {
Expand All @@ -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;
}
};
```
10 changes: 5 additions & 5 deletions Data-Structures/Trees/08-in-order-iterative.md
Original file line number Diff line number Diff line change
@@ -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 :**

Expand Down Expand Up @@ -73,7 +73,7 @@ Stack becomes :
### Implementation :

```cpp
/* Definition for binary tree :
/* Defination for binary tree :
struct TreeNode {
int val;
TreeNode *left;
Expand All @@ -90,7 +90,7 @@ class Solution {
vector<int> inorderTraversal(TreeNode* root) {

stack<TreeNode*> st; // declare a stack
vector<int>and; // declare an answer vector
vector<int> ans; // declare an answer vector

TreeNode* node = root; // take the root node

Expand All @@ -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;
}
};
```
12 changes: 6 additions & 6 deletions Data-Structures/Trees/09-pre-order-iterative.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,9 +29,9 @@ class Solution {
public:
vector<int> preorder(TreeNode* root) {

vectro<int>and;
vectro<int> ans;
if (root == NULL)
return and;
return ans;

stack<TreeNode*> st;
st.push(root);
Expand All @@ -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);
Expand All @@ -49,7 +49,7 @@ class Solution {
st.push(root->left);
}
}
return and;
return ans;
}
};
```
6 changes: 3 additions & 3 deletions Data-Structures/Trees/10-post-order-twoStack.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Solution {
public:
vector<int> postOrderTwoStack(TreeNode* root) {

vector<int>and;
vector<int> ans;
if (root == NULL)
return and;

Expand All @@ -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;
}
}
```
10 changes: 5 additions & 5 deletions Data-Structures/Trees/11-post-order-oneStack.md
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,9 +16,9 @@ right(right) {}
class Solution {
public:
vector<int> postOrderOneStack(TreeNode* root) {
vector<int>and;
vector<int> ans;
if (root == NULL)
return and;
return ans;

TreeNode* curr = root;
TreeNode* temp = NULL;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Data-Structures/Trees/problems/count-leaves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8238ae2

Please sign in to comment.