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

new branch with list and intermidiate solution of linked list #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Cayman4010
Copy link
Owner

No description provided.

Comment on lines +21 to +22
addNode.left = null;
addNode.right = null;

Choose a reason for hiding this comment

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

It's redundant initialisation

Suggested change
addNode.left = null;
addNode.right = null;

Comment on lines +28 to +29
if (value > thisNode.value) thisNode = thisNode.right;
if (value <= thisNode.value) thisNode = thisNode.left;

Choose a reason for hiding this comment

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

Use curly brackets for one-line if, please

Suggested change
if (value > thisNode.value) thisNode = thisNode.right;
if (value <= thisNode.value) thisNode = thisNode.left;
if (value > thisNode.value) {
thisNode = thisNode.right;
}
if (value <= thisNode.value) {
thisNode = thisNode.left;
}

}
if (value > thisNode.value) {
thisNode.right = addNode;
} else thisNode.left = addNode;

Choose a reason for hiding this comment

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

Same for else

root = addNode;
} else {
Node thisNode = root;
while (thisNode.right != null && thisNode.left != null) {

Choose a reason for hiding this comment

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

Wrong loop logic, I guess it's better to check whether thisNode != null

return false;
Node removeNode = root;
while (removeNode.value != value) {
if (value > removeNode.value) removeNode = removeNode.right;

Choose a reason for hiding this comment

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

same here

}

// Should remove specified value from tree and return true
// If value does not exist in this tree - return false
public boolean remove(int value) {
// TODO implement me
return false;
Node removeNode = root;
while (removeNode.value != value) {

Choose a reason for hiding this comment

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

what if removeNode == nul ??
Please, recheck loop condition

if (value > removeNode.value) removeNode = removeNode.right;
else removeNode = removeNode.left;
}
if (removeNode.value != value) return false;

Choose a reason for hiding this comment

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

You can set code formatting in IntelijiIdea as google code style.
And then you can format code in right way
https://stackoverflow.com/questions/42979700/how-to-configure-google-java-code-formatter-in-intellij-idea-17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants