Skip to content

Conversation

arjunjain8887
Copy link

  1. Memory Management: Used std::unique_ptr for automatic memory management, reducing the risk of memory leaks.

  2. STL Utilization: Replaced the custom queue implementation with std::queue, simplifying breadth-first traversal.

  3. Code Structure: Organized the code into a BinaryTree class, encapsulating the tree functionality and providing clearer interfaces for operations.

  4. Redundancy Reduction: Combined logic for finding and removing nodes to reduce redundancy, improving readability and maintainability.

  5. Error Handling: Added checks to handle cases where nodes may not be present during removal and traversal.

Description of Change

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

1. Memory Management:
Used std::unique_ptr for automatic memory management, reducing the risk of memory leaks.

2. STL Utilization:
Replaced the custom queue implementation with std::queue, simplifying breadth-first traversal.

3. Code Structure:
Organized the code into a BinaryTree class, encapsulating the tree functionality and providing clearer interfaces for operations.

4. Redundancy Reduction:
Combined logic for finding and removing nodes to reduce redundancy, improving readability and maintainability.

5. Error Handling:
Added checks to handle cases where nodes may not be present during removal and traversal.
Copy link
Collaborator

@realstealthninja realstealthninja left a comment

Choose a reason for hiding this comment

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

Thank you for your contributions. There are several issues to be addressed please fix them.

#include <memory>
#include <vector>
#include <queue>

Copy link
Collaborator

Choose a reason for hiding this comment

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

should be inside the datastructures namespace

*/
#include <iostream>
#include <memory>
#include <vector>
Copy link
Collaborator

Choose a reason for hiding this comment

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

headers should be documented


private:
// Helper function for insertion
void insertHelper(Node* node, int x) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could be inlined

root = std::make_unique<Node>(x); // Create root if it doesn't exist
} else {
Insert(n->left, x);
insertHelper(root.get(), x); // Helper function for recursive insertion
Copy link
Collaborator

Choose a reason for hiding this comment

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

should probably try to avoid recursion


// Remove a value from the tree
void remove(int x) {
removeHelper(root, x); // Helper function to manage removal
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of removeHelper why not _remove()?

}

// Postorder traversal
void postOrderTraversal() const {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use snake_case

int main() {
queue.front = 0;
queue.rear = 0;
BinaryTree tree;
Copy link
Collaborator

Choose a reason for hiding this comment

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

tests should be in a separate function called tests

@realstealthninja
Copy link
Collaborator

Your code doesn't compile. The above review is about the minor issues. The major issue is the improper use of templated functions

@realstealthninja realstealthninja added automated tests are failing Do not merge until tests pass requested changes changes have been requested labels Oct 1, 2024
@realstealthninja realstealthninja changed the title Update binary_search_tree.cpp feat: use smart pointer in binary search tree Oct 4, 2024
Copy link
Contributor

github-actions bot commented Nov 5, 2024

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.

@github-actions github-actions bot added the stale Author has not responded to the comments for over 2 weeks label Nov 5, 2024
Copy link
Contributor

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 or our Discord server. Thank you for your contributions!

@github-actions github-actions bot closed this Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automated tests are failing Do not merge until tests pass requested changes changes have been requested 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.

2 participants