Skip to content

Instantly share code, notes, and snippets.

View Giagnus64's full-sized avatar

Gianfranco Nuschese Giagnus64

View GitHub Profile
@Giagnus64
Giagnus64 / app.js
Last active September 20, 2021 06:52
Basic Tree Structure
class TreeNode {
constructor(value) {
this.value = value;
this.children = [];
}
}
class Tree {
constructor() {
this.root = null;
@Giagnus64
Giagnus64 / app.js
Last active May 28, 2021 23:22
Tree with Breadth First Search and Depth First Search
class TreeNode {
constructor(value) {
this.value = value;
this.children = [];
}
}
class Tree {
constructor() {
this.root = null;
@Giagnus64
Giagnus64 / app.js
Last active February 20, 2020 17:02
Binary Search Tree Implementation
class Node {
constructor(value){
this.value = value;
this.left = null;
this.right = null;
}
}
class BinarySearchTree {
constructor(){
@Giagnus64
Giagnus64 / app.js
Last active February 13, 2020 23:58
linked list implementation of queue
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
class Queue {
constructor(){
this.first = null;
@Giagnus64
Giagnus64 / app.js
Created February 12, 2020 16:42
Array implementation of queue using push and shift
// QUEUE = First In First Out
const queue = [];
queue.push("Resume.docx");
console.log(queue);
//[ 'Resume.docx' ]
queue.push("Data_Report.csv");
console.log(queue);
//["Resume.docx", "Data_Report.csv"]
@Giagnus64
Giagnus64 / app.js
Created February 12, 2020 16:41
Array implementation of a queue using unshift and pop
// QUEUE = First In First Out
const queue = [];
queue.unshift("Resume.docx");
console.log(queue);
//[ 'Resume.docx' ]
queue.unshift("Data_Report.csv");
console.log(queue);
@Giagnus64
Giagnus64 / app.js
Last active February 13, 2020 23:59
Linked list implementation of stack adding and removing to the beginning for constant time
class Node {
constructor(value) {
this.value = value;
this.next = null;
}
}
class Stack {
constructor(){
this.first = null;
@Giagnus64
Giagnus64 / app.js
Last active February 12, 2020 16:43
Array implementation of a stack using shift/unshift
//STACK = LAST IN FIRST OUT
const stack = [];
stack.unshift({"Willow Rosenberg": "A"});
console.log(stack);
//[{ "Willow Rosenberg": "A" }]
stack.unshift({"Xander Harris": "C"});
console.log(stack);
//[ { 'Xander Harris': 'C' }, { 'Willow Rosenberg': 'A' } ]
@Giagnus64
Giagnus64 / app.js
Last active February 12, 2020 16:43
Array implementation of a stack using push/pop
//STACK = LAST IN FIRST OUT
const stack = [];
stack.push({"Willow Rosenberg": "A"});
console.log(stack);
//[{ "Willow Rosenberg": "A" }]
stack.push({"Xander Harris": "C"});
console.log(stack);
//[{ "Willow Rosenberg": "A" }, { "Xander Harris": "C" }]
@Giagnus64
Giagnus64 / app.ts
Created February 6, 2020 00:35
Function Typing
//Incorrect!
function add(thing1: number, thing2: number): string{
return thing1 + thing2
}
function add(thing1: number, thing2: number): number{
return thing1 + thing2
}
function printGreeting(name: string): void{