-
-
Notifications
You must be signed in to change notification settings - Fork 7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: add comments and explanation to binary_search_tree.cpp data_structures #891
Conversation
…uctures test: add test for binary_search_tree.cpp data_structures fix: Remove() function bugs in binary_search_tree.cpp data_structures
This pull request introduces 1 alert when merging 6b10a56 into 8cd25f4 - view on LGTM.com new alerts:
|
rule of thumb - never use global variables unless absolutely necessary |
I will find another way to make it better. |
delete globle variable.
fix lgtm alerts: remove global variables. |
@liushubin-gitHub any update on this with fixing the errors? Thank you |
yes it is done . |
Thank you. |
yes,I will try my best to do it. |
Yes, there are some codes that are not properly documented. It is an ongoing effort to fic them: see for example #554 #555 |
Got it,i will try it again later |
Pls review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the dynamic memory and the errors reported by the automated tests
Pls help review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@ayaankhan98 please review as well. thanks.
could you add that in the |
* \param[in] x a node with value to be insert | ||
*/ | ||
void Insert(node* n, int x) { | ||
assert(n != NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if the user inserts the very first root element? this Insert function will break in that case. you are not handling the root insertition case, instead you assumed to insert the root value manually as mentioned in the test function
root->val = 4;
root->left = nullptr;
root->right = nullptr;
i suggest you to handle this too in the insert function because basically we are performing the very same operation that is we are insterting a value let it be anywhere in the tree either the root or the child everything should be properly handled by the same insert function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ayaankhan98 Thanks for you suggestion. I have got your means:
you want to design a function that is very common to use.
But , since here we are talking about a special tree (binary search tree).We need to insert a node from root node but can't from any children node (like a normal tree).
Another problem: it just assert and break the program when user take a wrong use of Insert() with a root node to be NULL .
I think with a kind use prompt for user .Maybe better than exit program.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have a look at this code that which i had written a year ago, i hope this makes you clear what i wish to say.
if (root == nullptr) {
Node* new_node = new Node;
new_node->data = data;
new_node->left = nullptr;
new_node->right = nullptr;
root = new_node;
}
if the root is null then we can do something like this. @liushubin-gitHub And i think this would be better instead of inserting the root node manually like
root->val = 4;
root->left = nullptr;
root->right = nullptr;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it.Thanks a lot!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice look at that link i had implemented some extra methods on BST, see if you can implement that in this PR.
@liushubin-gitHub if you face any problem let me know.
done |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert to last good code
revert to last good code。 This reverts commit adb42e4.
OK,done。 |
revert to last good code This reverts commit 19bdd29.
* \param[in] x a node with value to be insert | ||
*/ | ||
void Insert(node* root, int x) { | ||
if (root == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please consider the changes for the insert function which i suggested earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.i try early.but auto format checker failed.
you can get in commit:
adb42e4
so.i revert to last good code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liushubin-gitHub what was the actual error? is removing the code is only the solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (root == nullptr) {
root = std::shared_ptr<node>(new node);
root->val = x;
root->left = nullptr;
root->right = nullptr;
return;
}
could non_const reference be marked a warning instead of an error |
eca078d
to
a6a3b7d
Compare
This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel. Thank you for your contributions! |
Description of Change
This pull request make the following changes:
docs: add comments and explanation to binary_search_tree.cpp data_structures
test: add test for binary_search_tree.cpp data_structures
fix: Remove() function bugs in binary_search_tree.cpp data_structures
Checklist
@kvedala Pls, help review!
Notes: