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 Stack() { | |
this.count = 0; | |
this.storage = {}; | |
this.push = function (value) { | |
this.storage[this.count] = value; | |
this.count++; | |
} | |
this.pop = function () { |
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 Queue() { | |
var collection = []; | |
this.print = function () { | |
console.log(collection); | |
} | |
this.enqueue = function (element) { | |
collection.push(element); | |
} | |
this.dequeue = function () { | |
return collection.shift(); |
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 PriorityQueue() { | |
... | |
this.enqueue = function (element) { | |
if (this.isEmpty()) { | |
collection.push(element); | |
} else { | |
var added = false; | |
for (var i = 0; i < collection.length; i++) { |
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 pQ = new PriorityQueue(); | |
pQ.enqueue([ gannicus , 3]); | |
pQ.enqueue([ spartacus , 1]); | |
pQ.enqueue([ crixus , 2]); | |
pQ.enqueue([ oenomaus , 4]); | |
pQ.print(); |
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
[ | |
[ spartacus , 1 ], | |
[ crixus , 2 ], | |
[ gannicus , 3 ], | |
[ oenomaus , 4 ] | |
] |
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
/** Node in the linked list **/ | |
function Node(element) { | |
// Data in the node | |
this.element = element; | |
// Pointer to the next node | |
this.next = null; | |
} | |
function LinkedList() { | |
var length = 0; | |
var head = null; |
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 MySet() { | |
var collection = []; | |
this.has = function (element) { | |
return (collection.indexOf(element) !== -1); | |
} | |
this.values = function () { | |
return collection; | |
} | |
this.size = function () { | |
return collection.length; |
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 hash(string, max) { | |
var hash = 0; | |
for (var i = 0; i < string.length; i++) { | |
hash += string.charCodeAt(i); | |
} | |
return hash % max; | |
} | |
function HashTable() { | |
let storage = []; |
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
class Node { | |
constructor(data, left = null, right = null) { | |
this.data = data; | |
this.left = left; | |
this.right = right; | |
} | |
} | |
class BST { | |
constructor() { |
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
const bst = new BST(); | |
bst.add(4); | |
bst.add(2); | |
bst.add(6); | |
bst.add(1); | |
bst.add(3); | |
bst.add(5); | |
bst.add(7); | |
bst.remove(4); | |
console.log(bst.findMin()); |
OlderNewer