Skip to content

Instantly share code, notes, and snippets.

View samteb's full-sized avatar
🎯
Focusing

Samuel samteb

🎯
Focusing
View GitHub Profile
@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;
class Node {
constructor (val) {
this.val = val;
this.next = null;
}
}
class SinglyLinkedList {
constructor () {
this.head = null;
class Node {
constructor (val) {
this.val = val;
this.prev = null;
this.next = null;
}
}
class DoublyLinkedList {
constructor () {
class Node {
constructor (value) {
this.value = value;
this.left = null;
this.right = null;
}
}
class BinarySearchTree {
constructor () {
class MaxBinaryHeap {
constructor () {
this.values = [];
}
insert (value) {
this.values.push(value);
this.bubbleUp();
}
class Node {
constructor (value, priority) {
this.value = value;
this.priority = priority;
}
}
class PriorityQueue {
constructor () {
this.values = [];
class Graph {
constructor () {
this.adjacencyList = {};
}
addVertex (vertex) {
if (!this.adjacencyList[vertex]) this.adjacencyList[vertex] = [];
}
addEdge (vertex1, vertex2) {
class Node {
constructor (value, priority) {
this.value = value;
this.priority = priority;
}
}
class PriorityQueue {
constructor () {
this.values = [];
enum ListLevel {
AUTHORS = 'AUTHORS',
ARTICLES = 'ARTICLES'
}
interface Pagination {
first: number;
last: number;
}
this.listTitle$ = this.listLevel$.pipe(
map(listLevel => {
switch (listLevel) {
case ListLevel.AUTHORS:
return 'Trending authors that published few minutes ago!';
case ListLevel.ARTICLES:
return 'Best articles for you!';
default:
break;
}