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
4,323 changes: 0 additions & 4,323 deletions package-lock.json

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"description": "LambdaSchool's Data Structures I",
"main": "index.js",
"scripts": {
"test": "eslint tests/*.js && eslint src/*.js && jest --verbose",
"test": "jest --verbose",
"lint": "eslint",
"test:watch": "npm test -- --watch"
"test:watch": "yarn test -- --watchAll"
},
"repository": {
"type": "git",
Expand All @@ -20,7 +20,7 @@
"homepage": "https://github.com/SunJieMing/LS-Data-Structures-I/#readme",
"devDependencies": {
"babel-jest": "^19.0.0",
"eslint": "^3.17.1",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
Expand Down
53 changes: 53 additions & 0 deletions src/doubly-linked-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,59 @@
/* eslint-disable */

class DoublyLinkedList {
constructor() {
this.head = null;
this.tail = null;
}
// should have the methods "addToHead", "addToTail", "removeFromHead", "removeFromTail", "delete", "moveToFront", and "moveToBack"'
addToHead(value) {
let node = {
value,
next: null
};
if (this.head == null) {
this.head = node;
this.tail = node;
} else {
let oldHead = this.head;
this.head = node;
this.head.next = oldHead;
}
}
addToTail(value) {
let node = {
value,
next: null,
previous: this.tail
};
if (this.head == null) {
this.head = node;
this.tail = node;
}
else {
let oldTail = this.tail;
console.log('oldTail', oldTail)
oldTail.next = node;
this.tail = node;
// this.tail.previous = oldTail;
}
}
removeFromHead() {
let newHead = this.head.next;
this.head = newHead;
}
removeFromTail() {
return;
}
delete() {
return;
}
moveToFront() {
return;
}
moveToBack() {
return;
}
}

module.exports = DoublyLinkedList;
28 changes: 24 additions & 4 deletions src/hash-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ class HashTable {
// If no bucket has been created for that index, instantiate a new bucket and add the key, value pair to that new bucket
// If the key already exists in the bucket, the newer value should overwrite the older value associated with that key
insert(key, value) {

let hash = getIndexBelowMax(key, this.limit);
let bucket = this.storage.get(hash)

bucket.push([key, value]);
bucket.forEach((tuple, i) => {
if (tuple[0] == key) {
bucket.splice(i, 1, tuple);
}
});
if (this.storage.length > this.limit * 0.75) {
this.resize(2 * this.limit);
}
this.storage.set(hash, bucket);
}
// Removes the key, value pair from the hash table
// Fetch the bucket associated with the given key using the getIndexBelowMax function
Expand All @@ -27,8 +39,16 @@ class HashTable {
// 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) {

}
let hash = getIndexBelowMax(key, this.limit);
let bucket = this.storage.get(hash);
let match;

bucket.forEach((tuple) => {
if (tuple[0] == key) {
match = tuple[1];
}
});
}
}

module.exports = HashTable;
module.exports = HashTable;
31 changes: 27 additions & 4 deletions src/linked-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,41 @@ 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) {

let node = {
value,
next: null
};
if (this.head == null) {
this.head = node;
this.tail = node;
}
else {
let oldTail = this.tail;
oldTail.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() {

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

while (item) {
if (item.value == value) {
return true;
}
else {
item = item.next;
}
}
return false;
}
}

module.exports = LinkedList;
module.exports = LinkedList;
14 changes: 13 additions & 1 deletion src/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
4. Add a `dequeue` method that removes the item in the queue that was added earliest
*/
class Queue {

constructor() {
this.queue = []
}
get size(){
return this.queue.length;
}
enqueue(item) {
this.queue.push(item);
}
dequeue() {
let removed = this.queue.shift();
return removed;
}
}

module.exports = Queue;
16 changes: 14 additions & 2 deletions src/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
4. Add a `pop` method that removes the most recently-added item to the stack
*/
class Stack {

}
constructor() {
this.stack = []
}
get size() {
return this.stack.length;
}
push(item) {
this.stack.push(item)
}
pop() {
let popped = this.stack.pop();
return popped;
}
}

module.exports = Stack;
8 changes: 8 additions & 0 deletions src/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


babel@^6.23.0:
version "6.23.0"
resolved "https://registry.yarnpkg.com/babel/-/babel-6.23.0.tgz#d0d1e7d803e974765beea3232d4e153c0efb90f4"
integrity sha1-0NHn2APpdHZb7qMjLU4VPA77kPQ=
Loading