Add a check of the existance of a next node (#3051)
* Fix #2976 Co-authored-by: Sahil Prafulkumar Parekh <sh883193@dal.ca> Co-authored-by: Yang Libin <contact@yanglibin.info>
This commit is contained in:
parent
2a23770873
commit
6665ab262c
@ -89,7 +89,9 @@ public class HashMap {
|
|||||||
public void delete(int key) {
|
public void delete(int key) {
|
||||||
if (!isEmpty()) {
|
if (!isEmpty()) {
|
||||||
if (first.getKey() == key) {
|
if (first.getKey() == key) {
|
||||||
first = null;
|
Node next = first.next;
|
||||||
|
first.next = null; // help GC
|
||||||
|
first = next;
|
||||||
} else {
|
} else {
|
||||||
delete(first, key);
|
delete(first, key);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user