This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let Stack = (()=>{ | |
let map = new WeakMap(); | |
let _items = []; | |
class Stack { | |
constructor(...items){ | |
// let's store our items array inside the weakmap | |
map.set(this, []); | |
// let's get the items array from map, and store it in _items for easy access elsewhere |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Queue = (()=>{ | |
const map = new WeakMap(); | |
let _items = [] | |
class Queue{ | |
constructor(...items){ | |
//initialize the items in queue | |
map.set(this, []); | |
_items = map.get(this); | |
// enqueuing the items passed to the constructor | |
this.enqueue(...items) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Node(value, parent = null){ | |
this.value = value | |
this.left = null | |
this.right = null | |
this.parent = parent | |
} | |
// create tree |