Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4c101fb
added challenge 2
morgantatums Oct 3, 2019
4a18ce2
updated top level readme table of contents
morgantatums Oct 3, 2019
dd4a2c6
updated readme
morgantatums Oct 3, 2019
1b024ad
added code
morgantatums Oct 4, 2019
2546c80
working on test file
morgantatums Oct 4, 2019
29fd0d9
added uml
morgantatums Oct 4, 2019
c012a13
updated readme
morgantatums Oct 4, 2019
dee1727
fixed testing
morgantatums Oct 5, 2019
90ff151
fixed lint error
morgantatums Oct 5, 2019
cbd1b98
added basic files
morgantatums Oct 5, 2019
7857a03
added code and test
morgantatums Oct 5, 2019
9b717b2
updated readme
morgantatums Oct 5, 2019
de537cd
added comments to js file
morgantatums Oct 5, 2019
6961567
added UML
morgantatums Oct 6, 2019
dd4ef6e
fixed readme path
morgantatums Oct 8, 2019
dc11cc1
updated repo for 5
morgantatums Oct 16, 2019
7a76832
added insert before function and tests
morgantatums Oct 18, 2019
953a296
finished final
morgantatums Oct 18, 2019
991741f
updated readme
morgantatums Oct 18, 2019
71d5162
updated reamde
morgantatums Oct 21, 2019
332db58
added starter
morgantatums Oct 24, 2019
89384fc
completed function, working on tests
morgantatums Oct 24, 2019
bf1e12c
completed tests
morgantatums Oct 24, 2019
a2a37b4
fixed folder name
morgantatums Oct 26, 2019
63ef93f
added starter code
morgantatums Oct 26, 2019
af2a9da
finished most tests
morgantatums Oct 29, 2019
a05c28b
completed functions
morgantatums Oct 29, 2019
151cd5c
updated readme
morgantatums Oct 29, 2019
e7b0a11
turned off other tests
morgantatums Nov 2, 2019
1cd5936
updated readme
morgantatums Nov 2, 2019
80dae55
tried to fix lint
morgantatums Nov 2, 2019
d85e915
added travis to readme
morgantatums Nov 2, 2019
dfe56de
started on challenge
morgantatums Nov 7, 2019
dc860e0
finished final functions
morgantatums Nov 8, 2019
7897aab
finished readme
morgantatums Nov 8, 2019
b05bccb
updated travis url
morgantatums Nov 8, 2019
83fe781
updated readme
morgantatums Nov 8, 2019
765e493
set up files
morgantatums Nov 12, 2019
9669851
added some additional code
morgantatums Nov 15, 2019
3a6a0e8
added binary search tree
morgantatums Nov 22, 2019
e91aa0f
added starter code
morgantatums Nov 22, 2019
7d90d4e
added readme links
morgantatums Nov 22, 2019
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
8 changes: 8 additions & 0 deletions Data-Structures/LinkList/__tests__/linked-list.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const LinkList = require('../linked-list.js');

xdescribe('Test', () => {
// How might we repeat this to check on types?
it('true', ()=>{
expect(LinkList).toBeTruthy();
});
});
Empty file.
22 changes: 22 additions & 0 deletions Data-Structures/LinkList/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Singly Linked List

<!-- Short summary or background information -->

## Challenge
Write tests to prove the following functionality:

* Can successfully instantiate an empty linked list
* Can properly insert into the linked list
* The head property will properly point to the first node in the linked list
* Can properly insert multiple nodes into the linked list
* Will return true when finding a value within the linked list that exists
* Will return false when searching for a value in the linked list that does not exist
* Can properly return a collection of all the values that exist in the linked list

## Approach & Efficiency

<!-- What approach did you take? Why? What is the Big O space/time for this approach? -->

## API

<!-- Description of each method publicly available to your Linked List -->
150 changes: 150 additions & 0 deletions Data-Structures/ll-Insertions/__tests__/linked-list.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
const LinkedList = require('../linked-list.js');

xdescribe('Test', () => {
it('true', ()=>{
expect(true).toBeTruthy();
});
});

// * Can successfully instantiate an empty linked list
xdescribe('instantiate an empty linked list', ()=>{
let list = new LinkedList();
it('empty list',()=>{
expect(list).toBeTruthy();
});
});

// * Can properly insert into the linked list
xdescribe('insert into the linked list', ()=>{
let list = new LinkedList();
list.insert('yellow');

it('successfully inserts into list', ()=>{
expect(list.head.data).toBe('yellow');

});

});
// * The head property will properly point to the first node in the linked list
xdescribe('The head property will properly point to the first node in the linked list', ()=>{
let list = new LinkedList();
list.insert('yellow');
list.insert('blue');

it('first node is correct', ()=>{
expect(list.head.data).toBe('blue');
});

});
// * Can properly insert multiple nodes into the linked list
xdescribe('Can properly insert multiple nodes into the linked list', ()=>{
let list = new LinkedList();
list.insert('yellow');
list.insert('blue');

it('successfully added head', ()=>{
expect(list.head.data).toBe('blue');
});
it('successfully added 2nd value', ()=>{
expect(list.head.next.data).toBe('yellow');
});
});

xdescribe('Will return true when finding a value within the linked list that exists', ()=>{
let list = new LinkedList();
list.insert('yellow');
list.insert('blue');
let searchResult = list.includes('yellow');
let badSearchResult = list.includes('apple');

// Will return true when finding a value within the linked list that exists
it('Returns true for items that exist', ()=>{
expect(searchResult).toBeTruthy();
});
// * Will return false when searching for a value in the linked list that does not exist
it('Returns false for items that do not exist', ()=>{
expect(badSearchResult).toBeFalsy();
});
});


// * Can properly return a collection of all the values that exist in the linked list
xdescribe('Can properly return a collection of all the values that exist in the linked list', ()=>{
let list = new LinkedList();
list.insert('yellow');
list.insert('blue');
list.insert('green');
let allItems = list.toString();
it('returns a collection', ()=>{
expect(allItems).toBe('green,blue,yellow');
});

});

// Can successfully add a node to the end of the linked list
xdescribe('Can successfully add a node to the end of the linked list', ()=>{
let list = new LinkedList();
list.insert('yellow');
list.append('green');
list.append('blue');

it('Items should be added to the end of the list', ()=>{
expect(list.head.next.data).toBe('green');
});
// Can successfully add multiple nodes to the end of a linked list
it('Can add multiple nodes to the end of a list',()=>{
expect(list.head.next.next.data).toBe('blue');
});

});

// Can successfully insert a node before a node located in the middle of a linked list

xdescribe('Can successfully insert a node before a node located in the middle of a linked list', ()=>{
let list = new LinkedList();
list.insert('yellow');
list.append('blue');
list.insertBefore('green', 'blue');
it('inserts in middle', ()=>{
expect(list.head.next.data).toBe('green');
});
it('blue should be at the end', ()=>{
expect(list.head.next.next.data).toBe('blue');
});
it('head should stay the same', ()=>{
expect(list.head.data).toBe('yellow');
});
});
// Can successfully insert a node before the first node of a linked list
xdescribe('Can successfully insert a node before a node located in the middle of a linked list', ()=>{
let list = new LinkedList();
list.insert('yellow');
list.append('blue');
list.insertBefore('green', 'yellow');
it('inserts at the head', ()=>{
expect(list.head.data).toBe('green');
});
it('blue should be at the end', ()=>{
expect(list.head.next.next.data).toBe('blue');
});
it('head should move over', ()=>{
expect(list.head.next.data).toBe('yellow');
});
});
// Can successfully insert after a node in the middle of the linked list
xdescribe('Can successfully insert a node after a node located in the middle of a linked list', ()=>{
let list = new LinkedList();
list.insert('yellow');
list.append('blue');
list.insertAfter('green', 'yellow');
it('head stays the same', ()=>{
expect(list.head.data).toBe('yellow');
});
it('blue should be at the end', ()=>{
expect(list.head.next.next.data).toBe('blue');
});
it('new node should be in the middle', ()=>{
expect(list.head.next.data).toBe('green');
});
});
// Can successfully insert a node after the last node of the linked list
89 changes: 89 additions & 0 deletions Data-Structures/ll-Insertions/linked-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
const Node = require('./node.js');

// instantiate an empty linked list
class LinkedList {
constructor(){
this.head = null;
}
// insert item into the beginning of the list
insert(data){
let inserted = new Node(data);
inserted.next = this.head;
this.head = inserted;
return this.head;
}
// A function called includes which takes in a value and returns a boolean if that value exists in the linked list
includes(searchValue) {
let currentNode = this.head;
while(currentNode) {
if (currentNode.data === searchValue){
return true;
}
currentNode = currentNode.next;
}
return false;
}
// A function called toString which takes in no arguments and returns a string representing all the values in the linked list
toString(){
let stringList = [];
let currentNode = this.head;
while(currentNode){
stringList.push(currentNode.data);
currentNode = currentNode.next;
}
return stringList.toString();

}
// A function called append which adds a Node to the end of the list
append(data){
let appendedItem = new Node(data);
let currentNode = this.head;
if(this.head === null){
this.head = appendedItem;
return this.head;
} else{
while(currentNode.next){
currentNode = currentNode.next;
}
currentNode.next = appendedItem;
}
}
insertBefore(data, before){
let insertedItem = new Node(data);
let currentNode = this.head;
if(currentNode.data === before){
this.insert(data);
return;
}

while(currentNode.next){
if(currentNode.next.data === before){
insertedItem.next = currentNode.next;
currentNode.next = insertedItem;
return;
}
currentNode = currentNode.next;
}

}

insertAfter(data, after){
let insertedItem = new Node(data);
let currentNode = this.head;

while(currentNode){
if(currentNode.data === after){
insertedItem.next = currentNode.next;
currentNode.next = insertedItem;
return;
}
currentNode = currentNode.next;
}

}


}


module.exports = LinkedList;
10 changes: 10 additions & 0 deletions Data-Structures/ll-Insertions/node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

class Node {
constructor(value){
this.data = value;
this.next = null;
}
}

module.exports = Node;
43 changes: 43 additions & 0 deletions Data-Structures/ll-Insertions/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Singly Linked List

More complex functions for singly linked lists

## Challenge
* Have a class named Node. This class should contain:
A variable to hold data (i.e. this.data)
A variable to hold the next Node object (i.e. this.next)
* Have a class named LinkedList. This class should contain:
A variable named head which holds the Node object that starts the list
A constructor that instantiates head as an empty linked list
A function called insert which takes in a value. This function will then create a new Node object, sets the object’s data property equal to the value. The function then appends this new Node object to the beginning of the linked list (i.e. it sets a new head)
A function called includes which takes in a value and returns a boolean if that value exists in the linked list
A function called toString whcih takes in no arguments and returns a string representing all the values in the linked list
A function called append which adds a Node to the end of the list
A function called insertBefore which adds a Node before a certain Node in the list
A function called insertAfter which adds a Node after a certain Node in the list
Implement good error checking throughout your code. Create custom errors that describe what went wrong.
Structure and Testing
Any functions you write should be clean, reusable and independent component parts to the whole program.

#### Write tests to prove the following functionality:

* Can successfully add a node to the end of the linked list
* Can successfully add multiple nodes to the end of a linked list
* Can successfully insert a node before a node located in the middle of a linked list
* Can successfully insert a node before the first node of a linked list
* Can successfully insert after a node in the middle of the linked list
* Can successfully insert a node after the last node of the linked list

## Approach & Efficiency

O(n)
We never go deeper than one interation of the list so Big O(n) is still applicable

## API

insert(data) - Creates a new Node Object. Appends the new Node object to the beginning of the linked list
includes(searchValue) - Takes in a value as a paramenter and returns a boolean if the value exists in the linked list
toString() - Returns a string with all the values in the linked list
append(data) - Adds a node to the end of the list
insertBefore(data, before) - Adds a Node before a certain Node in the list
insertAfter(data, after) - Adds a Node after a certain Node in the list
Loading