Visitar URL original
Java/DataStructures/HashMap/Hashing/HashMap.java. In line100-108, method delete has some problems. · Issue #1448 · TheAlgorithms/Java · GitHub
The Wayback Machine - https://web.archive.org/web/20201103192746/https://github.com/TheAlgorithms/Java/issues/1448
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

Java/DataStructures/HashMap/Hashing/HashMap.java. In line100-108, method delete has some problems. #1448

Open
xiao1i opened this issue Sep 7, 2020 · 1 comment

Comments

@xiao1i
Copy link

@xiao1i xiao1i commented Sep 7, 2020

In method delete(Node,int key),if i set hsize=3,then add 2,5,8,11in the bucket 2.When i want to delete 11,this method doesn't work.I think it should be modified as follows:

private void delete(Node n, int key) {
if(n.getNext().getKey() == key) {
if(n.getNext().getNext() == null) {
n.setNext(null);
} else {
n.setNext(n.getNext().getNext());
}
} else {
delete(n.next,key);
}
}

@BridBlue
Copy link

@BridBlue BridBlue commented Sep 14, 2020

Hashmap.Node.getKey() return an Object ,so you should try to use equals()

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

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.