X Tutup
The Wayback Machine - https://web.archive.org/web/20200916202146/https://github.com/williamfiset/Algorithms/pull/175
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

Added Remove Method To Red Black Tree #175

Merged
merged 14 commits into from May 12, 2020
Merged

Conversation

@nishantc1527
Copy link
Contributor

nishantc1527 commented May 9, 2020

resolves #80

@nishantc1527
Copy link
Contributor Author

nishantc1527 commented May 9, 2020

Ok I got the google java style guide. Sorry for the messiness, I just learned how to enable google java style guide.

public void testNumberDoesntExist() {
assertFalse(tree.delete(0));
}

/*
@Test
public void randomRemoveTests() {

This comment has been minimized.

@williamfiset

williamfiset May 10, 2020 Owner

Can you uncomment the randomTemoveTests method? You may need to adapt it to work, but it should catch any bugs

This comment has been minimized.

@nishantc1527

nishantc1527 May 10, 2020 Author Contributor

Oh, sorry about that. By the way (this is not a hate comment, just a suggestion), it would much easier if instead of null checks, you used a constant field called NIL or something which is a node with the color of black, the left child is NIL, the right child is NIL, and the parent is NIL. So, instead of constantly doing if(node == null || node.color == BLACK) you can do if(node.color == BLACK). Like I said, just a suggestion. I didn't change it because you were the original author.

@nishantc1527
Copy link
Contributor Author

nishantc1527 commented May 10, 2020

Yeah I need to add quite a few null checks. My original source code didn't account for this.

@nishantc1527
Copy link
Contributor Author

nishantc1527 commented May 11, 2020

I need to redo some stuff. I'll come back in a bit.

}

@Test
public void testTreeHeight() {

This comment has been minimized.

@williamfiset

williamfiset May 11, 2020 Owner

Don't feel the need to include the tree height test and method if it's causing a headache. This is more important for AVL trees than for RB trees. Feel free to remove if you want.

This comment has been minimized.

@nishantc1527

nishantc1527 May 11, 2020 Author Contributor

Oh thanks! But it wasn't that, there were some bugs in my actual delete method, and since I made some stuff really messy, I'm thinking of redoing it. It won't be much though, since all I need to do is copy and paste my source code.

@nishantc1527
Copy link
Contributor Author

nishantc1527 commented May 11, 2020

If it's fine with you, I'm going to change most of the stuff by adding the NIL change I was talking about earlier. When I push it, you can tell me to delete it if you want.

@nishantc1527
Copy link
Contributor Author

nishantc1527 commented May 11, 2020

Ok, so when adding the NIL node, I had to change a lot of stuff in the original insert method. If you want, I'll try my best to make it look as similar as possible to what it looked like before. However, working without the NIL node is like not having a pointer to the parent node. It's possible, but much harder.

@williamfiset
Copy link
Owner

williamfiset commented May 12, 2020

The NIL node is fine, I can see how it would be a pain to reach into nested references while constantly checking for null. Thanks for reworking this and making the tests pass :)

@williamfiset williamfiset merged commit 91998a3 into williamfiset:master May 12, 2020
3 checks passed
3 checks passed
build
Details
build
Details
build
Details
williamfiset pushed a commit that referenced this pull request May 12, 2020
William Fiset William Fiset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.
X Tutup