Skip to content

Instantly share code, notes, and snippets.

View boxgames1's full-sized avatar
🏈
Over the scrimmage line

Oliver Alonso boxgames1

🏈
Over the scrimmage line
View GitHub Profile
@boxgames1
boxgames1 / Single_vs_Double_Linked_Lists.csv
Last active June 16, 2018 09:10
Single vs Double Linked Lists. Method costs comparision
Method Single Double
Insert O(n) O(1)
Erase O(n) O(1)
Find O(n) O(n)
Clear O(n) O(n)
Empty O(1) O(1)
Begin O(1) O(1)
End O(n) O(1)
@boxgames1
boxgames1 / chocri_script.js
Created June 22, 2018 11:15
Chocri Script
class Team {
constructor(name, zone){
this.zone = zone;
this.name = name;
}
}
class Game {
constructor (team1, team2, week){
this.team1 = team1;
@boxgames1
boxgames1 / BinaryNode.js
Created June 29, 2018 10:56
Binary Node
class BinaryNode {
constructor(key, value) {
this.value = value;
this.key = key;
this.left = null;
this.right = null;
}
// Cost: O(1)
free() {
this.left = null;
@boxgames1
boxgames1 / BinaryTreeInsertion.js
Created June 29, 2018 11:02
BinaryTreeInsertion
insert(key, value) {
if (!Number.isInteger(key)) return;
const newNode = new BinaryNode(key, value);
if (this.root === null) this.root = newNode;
else this.insertNode(this.root, newNode);
}
insertNode(node, newNode) {
if (newNode.key < node.key) {
if (node.left === null) node.left = newNode;
@boxgames1
boxgames1 / BinaryTreeRemoval.js
Last active June 29, 2018 11:14
BinaryTreeRemoval
remove(key) {
if (!Number.isInteger(key)) return;
this.root = this.removeNode(this.root, key);
}
removeNode(node, key) {
if (node === null) return null;
else if (key < node.key) {
node.left = this.removeNode(node.left, key);
return node;
} else if (key > node.key) {
@boxgames1
boxgames1 / BinaryTreeInorder.js
Last active June 29, 2018 11:25
BinaryTreeInorder
inorder(node, fn) {
if (node !== null) {
this.inorder(node.left, fn);
fn(node);
this.inorder(node.right, fn);
}
}
@boxgames1
boxgames1 / BinaryTreePreorder.js
Last active June 29, 2018 11:25
BinaryTreePreorder
preorder(node, fn) {
if (node !== null) {
fn(node);
this.preorder(node.left, fn);
this.preorder(node.right, fn);
}
}
@boxgames1
boxgames1 / BinaryTreePostorder.js
Created June 29, 2018 11:24
BinaryTreePostorder
postorder(node, fn) {
if (node !== null) {
this.postorder(node.left, fn);
this.postorder(node.right, fn);
fn(node);
}
}
@boxgames1
boxgames1 / BinaryTreeLevelorder.js
Created June 29, 2018 11:25
BinaryTreeLevelorder
levelOrder() {
if (!this.root) return [];
var array = [];
search(this.root, 1, 1);
function search(node, level, index) {
if (node) {
const count = Math.pow(2, level - 1);
if (array.length < level) {
array.push(Array(count).fill(""));
@boxgames1
boxgames1 / BinaryTreeFind.js
Created June 29, 2018 12:45
BinaryTreeFind
find(node, key) {
if (node === null) return null;
else if (key < node.key) return this.find(node.left, key);
else if (key > node.key) return this.find(node.right, key);
else return node;
}