Skip to content
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

Closed
wants to merge 49 commits into from

Conversation

liushubin-gitHub
Copy link
Contributor

@liushubin-gitHub liushubin-gitHub commented Jun 24, 2020

Description of Change

This pull request make the following changes:

  1. docs: add comments and explanation to binary_search_tree.cpp data_structures

  2. test: add test for binary_search_tree.cpp data_structures

  3. fix: Remove() function bugs in binary_search_tree.cpp data_structures

Checklist

  • Added description of change
  • [x ] PR title follows semantic commit guidelines
  • [x ] Search previous suggestions before making a new one, as yours may be a duplicate.
  • [x ] I acknowledge that all my contributions will be made under the project's license.

@kvedala Pls, help review!
Notes:

liushubin lwx470335 and others added 3 commits June 24, 2020 14:25
…uctures

test: add test for binary_search_tree.cpp data_structures
fix: Remove() function bugs in binary_search_tree.cpp data_structures
@lgtm-com
Copy link

lgtm-com bot commented Jun 25, 2020

This pull request introduces 1 alert when merging 6b10a56 into 8cd25f4 - view on LGTM.com

new alerts:

  • 1 for Short global name

@kvedala
Copy link
Collaborator

kvedala commented Jun 25, 2020

rule of thumb - never use global variables unless absolutely necessary

@liushubin-gitHub
Copy link
Contributor Author

I will find another way to make it better.

@liushubin-gitHub
Copy link
Contributor Author

fix lgtm alerts: remove global variables.

@kvedala
Copy link
Collaborator

kvedala commented Jul 3, 2020

@liushubin-gitHub any update on this with fixing the errors? Thank you

@liushubin-gitHub
Copy link
Contributor Author

yes it is done .
lgtm has passed

@kvedala
Copy link
Collaborator

kvedala commented Jul 3, 2020

yes it is done .
lgtm has passed

Thank you.
There are still undocumented structures and functions. Can you please document them as well.

@liushubin-gitHub
Copy link
Contributor Author

yes it is done .
lgtm has passed

Thank you.
There are still undocumented structures and functions. Can you please document them as well.

yes,I will try my best to do it.
But there is still some functions that i don't understand clearly,so i just leave it empty. (as i am not the original author)
Also, there should be some document about test cases , but i think not so much important (test code is clearly enough), then i just skip :)

@kvedala
Copy link
Collaborator

kvedala commented Jul 3, 2020

yes it is done .
lgtm has passed

Thank you.
There are still undocumented structures and functions. Can you please document them as well.

yes,I will try my best to do it.
But there is still some functions that i don't understand clearly,so i just leave it empty. (as i am not the original author)
Also, there should be some document about test cases , but i think not so much important (test code is clearly enough), then i just skip :)

Yes, there are some codes that are not properly documented. It is an ongoing effort to fic them: see for example #554 #555
Leaving code half-fixed will lead to issues in maintaining them as they will be inconsistent and contributors can have the wrong idea. Moreover, the repo auto-generates a documentation website - https://thealgorithms.github.io/C that will not render correctly if code is only half fixed.

@liushubin-gitHub
Copy link
Contributor Author

yes it is done .
lgtm has passed

Thank you.
There are still undocumented structures and functions. Can you please document them as well.

yes,I will try my best to do it.
But there is still some functions that i don't understand clearly,so i just leave it empty. (as i am not the original author)
Also, there should be some document about test cases , but i think not so much important (test code is clearly enough), then i just skip :)

Yes, there are some codes that are not properly documented. It is an ongoing effort to fic them: see for example #554 #555
Leaving code half-fixed will lead to issues in maintaining them as they will be inconsistent and contributors can have the wrong idea. Moreover, the repo auto-generates a documentation website - https://thealgorithms.github.io/C that will not render correctly if code is only half fixed.

Got it,i will try it again later

@liushubin-gitHub
Copy link
Contributor Author

Pls review!

@kvedala
Copy link
Collaborator

kvedala commented Jul 10, 2020

Screenshot_20200710-081244.png
Please fix the errors reported by the system. You can click on "details" to see the error details

Copy link
Collaborator

@kvedala kvedala left a 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

data_structures/binary_search_tree.cpp Outdated Show resolved Hide resolved
@kvedala
Copy link
Collaborator

kvedala commented Jul 10, 2020

image
please check the errors reported

@liushubin-gitHub
Copy link
Contributor Author

image
please check the errors reported

i found the code format fail has been auto corrected by the code formatter!

@kvedala
Copy link
Collaborator

kvedala commented Jul 10, 2020

image
please check the errors reported

i found the code format fail has been auto corrected by the code formatter!

I don't think so. Can you show me where you see that?
Did you actually click the details link and see the error message?

@liushubin-gitHub
Copy link
Contributor Author

Pls help review!

kvedala
kvedala previously approved these changes Jul 15, 2020
Copy link
Collaborator

@kvedala kvedala left a 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.

@kvedala
Copy link
Collaborator

kvedala commented Jul 15, 2020

could you add that in the std::out statements that any other number will exit

* \param[in] x a node with value to be insert
*/
void Insert(node* n, int x) {
assert(n != NULL);
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/ayaankhan98/DSA_competative/blob/b1d200d8a9614141fa1305f1e41c605526e91336/Data_Structures/Trees/BST.cpp#L25

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;

Copy link
Contributor Author

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!

Copy link
Member

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.

@liushubin-gitHub
Copy link
Contributor Author

any other number will exit

done

@kvedala
Copy link
Collaborator

kvedala commented Jul 16, 2020

image
@liushubin-gitHub It seems your latest push broke the code. Please revert to the last known good code.

Copy link
Contributor Author

@liushubin-gitHub liushubin-gitHub left a 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.
@liushubin-gitHub
Copy link
Contributor Author

image
@liushubin-gitHub It seems your latest push broke the code. Please revert to the last known good code.

OK,done。

@kvedala kvedala requested a review from ayaankhan98 July 17, 2020 23:05
* \param[in] x a node with value to be insert
*/
void Insert(node* root, int x) {
if (root == NULL) {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Member

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;
}

@liushubin-gitHub
Copy link
Contributor Author

could non_const reference be marked a warning instead of an error
Pls review!

@stale
Copy link

stale bot commented Jul 1, 2021

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.

@stale stale bot added the stale Author has not responded to the comments for over 2 weeks label Jul 1, 2021
@stale stale bot removed the stale Author has not responded to the comments for over 2 weeks label Jul 29, 2021
@stale
Copy link

stale bot commented Aug 28, 2021

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.

@stale stale bot added the stale Author has not responded to the comments for over 2 weeks label Aug 28, 2021
@stale
Copy link

stale bot commented Sep 6, 2021

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!

@stale stale bot closed this Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Author has not responded to the comments for over 2 weeks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants