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:
Sahil Parekh 2022-06-29 09:02:40 -03:00 committed by GitHub
parent 2a23770873
commit 6665ab262c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,7 +89,9 @@ public class HashMap {
public void delete(int key) {
if (!isEmpty()) {
if (first.getKey() == key) {
first = null;
Node next = first.next;
first.next = null; // help GC
first = next;
} else {
delete(first, key);
}