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(value) { | |
this.value = value; | |
this.next = null; | |
} | |
} | |
class Queue { | |
constructor() { | |
this.first = 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
class Stack { | |
constructor() { | |
this.list = []; | |
} | |
// Peek the top element. | |
peek() { | |
this.list.length ? console.log(this.list[this.list.length - 1]) : console.log('The stack is empty.'); | |
return this.list.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
class Node { | |
constructor(value) { | |
this.value = value; | |
this.next = null; | |
} | |
} | |
class Stack { | |
constructor() { | |
this.top = 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
class Node { | |
constructor(value) { | |
this.value = value; | |
this.next = null; | |
this.previous = null; | |
} | |
} | |
class DoublyLinkedList { | |
constructor(value) { |
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
// Creating node | |
class Node { | |
constructor(value) { | |
this.value = value; | |
this.next = null; | |
} | |
} | |
class LinkedList { | |
// Empty Linked List will not be formed. |
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 HashTable { | |
constructor(size) { | |
this.data = new Array(size); | |
} | |
// Hash Function | |
_hash(key) { | |
let hash = 0; | |
for(let i = 0; i < key.length; i++) { | |
hash = (hash + key.charCodeAt(i) * i) % this.data.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
class HashTable { | |
constructor(size) { | |
this.data = new Array(size); | |
} | |
// Hash Function | |
_hash(key) { | |
let hash = 0; | |
for (let i = 0; i < key.length; i++) { | |
hash = (hash + key.charCodeAt(i) * i) % this.data.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
/** | |
* @param {string} word | |
* @return {boolean} | |
* true if palindrome else false | |
*/ | |
function isPalindrome (word) { | |
if (word) { | |
return word.toLowerCase() === word.toLowerCase().split('').reverse().join('') ? true : false; | |
} else { | |
return false; |
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
// Implement Array in JavaScript | |
class OurArray { | |
constructor () { | |
this.length = 0; | |
this.data = {}; // An array in JavaScript is Object | |
} | |
/** Lookup: Time Complexity = O(1) | |
* @param {number} index |
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 OurArray { | |
constructor () { | |
this.length = 0; | |
this.data = {}; // An array in JavaScript is Object | |
} | |
/** Lookup: Time Complexity = O(1) | |
* @param {number} index | |
* @return {any} item | |
*/ |