Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/hash-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ class HashTable {
// If the key already exists in the bucket, the newer value should overwrite the older value associated with that key
insert(key, value) {

}
};
// Removes the key, value pair from the hash table
// Fetch the bucket associated with the given key using the getIndexBelowMax function
// Remove the key, value pair from the bucket
remove(key) {
}

};

// Fetches the value associated with the given key from the hash table
// Fetch the bucket associated with the given key using the getIndexBelowMax function
// Find the key, value pair inside the bucket and return the value
retrieve(key) {
}

};
}

module.exports = HashTable;
32 changes: 30 additions & 2 deletions src/linked-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,45 @@ class LinkedList {
// If the list is empty, the new element is considered the tail as well as the head
// If there is one element in the list before the new element is added, the new element becomes the tail of the list
addToTail(value) {
const node = {
next: null,
value,
};

if (this.tail === null) {
this.tail = node;
this.head = node;
return;
}
this.tail.next = node;
this.tail = node;
}
// Removes the current head node from the list, replacing it with the next element in the list
// Returns the value of the removed node
removeHead() {

if (this.head === null) {
return;
}
const value = this.head.value;
this.head = this.head.next;
return value;
}
// Checks the linked list for the given value
// Returns true if the the value is found in the list, false otherwise
contains(value) {

if (this.head === null) {
return false;
}
const find = (node) => {
if (node.value === value) {
return true;
}
if (node.next === null) {
return false;
}
return (find(node.next));
};
return (find(this.head));
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,24 @@
4. Add a `dequeue` method that removes the item in the queue that was added earliest
*/
class Queue {
constructor() {
this.storage = [];
}

get size() {
return this.storage.length;
}

enqueue(item) {
this.storage.push(item);
return this.size;
}

dequeue(item) {
return this.storage.shift(item);
}

}


module.exports = Queue;
17 changes: 17 additions & 0 deletions src/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
4. Add a `pop` method that removes the most recently-added item to the stack
*/
class Stack {
constructor() {
this.storage = [];
this.counter = 0;
}

get size() {
return this.counter;
}

push(item) {
this.storage.push(item);
return this.counter++;
}

pop(item) {
return this.storage.pop(item);
}

}

Expand Down