addressed issue 1033, changed while to if in LinkedList and add new before Array in HashTable constructor

This commit is contained in:
tmichell13 2023-05-08 16:19:27 -04:00
parent 8c5e5f4f0d
commit 085bb2973e
2 changed files with 2 additions and 2 deletions

View File

@ -12,7 +12,7 @@ export default class HashTable {
*/
constructor(hashTableSize = defaultHashTableSize) {
// Create hash table of certain size and fill each bucket with empty linked list.
this.buckets = Array(hashTableSize).fill(null).map(() => new LinkedList());
this.buckets = new Array(hashTableSize).fill(null).map(() => new LinkedList());
// Just to keep track of all actual keys in a fast way.
this.keys = {};

View File

@ -101,7 +101,7 @@ export default class LinkedList {
// If the head must be deleted then make next node that is different
// from the head to be a new head.
while (this.head && this.compare.equal(this.head.value, value)) {
if (this.head && this.compare.equal(this.head.value, value)) {
deletedNode = this.head;
this.head = this.head.next;
}