Skip to content

Instantly share code, notes, and snippets.

View samteb's full-sized avatar
🎯
Focusing

Samuel samteb

🎯
Focusing
View GitHub Profile
class Node {
constructor (value) {
this.value = value;
this.left = null;
this.right = null;
}
}
class BinarySearchTree {
constructor () {
class Node {
constructor (val) {
this.val = val;
this.prev = null;
this.next = null;
}
}
class DoublyLinkedList {
constructor () {
class Node {
constructor (val) {
this.val = val;
this.next = null;
}
}
class SinglyLinkedList {
constructor () {
this.head = null;
@samteb
samteb / sorting-algorithms.js
Created May 26, 2019 05:17
Sorting Algorithms
const swap = (arr, idx1, idx2) => {
[ arr[idx1], arr[idx2] ] = [ arr[idx2], arr[idx1] ];
};
/*********** Bubble Sort O(n^2) ***********/
const bubbleSort = (arr) => {
let noSwaps;
for (let i = arr.length; i > 0; i--) {
noSwaps = true;