This file contains hidden or 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 basicPartition(data, begin, end){ | |
const pivot = data[begin]; | |
let rightBegin = begin+1; | |
for(let i=rightBegin; i<=end; i++){ | |
if(data[i] < pivot){ | |
swap(data, i, rightBegin); | |
rightBegin++; | |
} | |
} | |
const mid = rightBegin-1; |
This file contains hidden or 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
program add_one: | |
input => num_1 | |
num_1 + 1 => sum | |
sum => output | |
program main: | |
input list => numbers | |
0 => sum | |
each input => item | |
if item > 0 |
This file contains hidden or 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
using System; | |
namespace Quick | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var data = new int[] { 5, 2, 7, 4, 1, 6, 3 }; | |
Quicksort(data, 0, data.Length-1); |
This file contains hidden or 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
// abstract | |
function makeCount(limit, abstractMethods){ | |
let state = 0; | |
const _state = function(stateChange){ | |
if(stateChange === undefined) | |
return state; | |
else | |
state = stateChange(state); |
This file contains hidden or 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
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <vector> | |
#include <iterator> | |
#include <limits> | |
using namespace std; | |
using Data = vector<int>; | |
using Words = vector<string>; |
This file contains hidden or 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 createMockFetch(map){ | |
return function(url){ /* fetch mock */ | |
return { /* promise mock */ | |
then: function(){ | |
return { /* another promise mock */ | |
then: function(cb){ | |
let mockJson = map[url](); | |
cb(mockJson); | |
} | |
}; |
This file contains hidden or 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 SwappableData(nums: Int*){ | |
private val data: Array[Int] = nums.toArray | |
def swap(a: Int, b: Int): Unit = { | |
if(a != b){ | |
val x = data(a) | |
data(a) = data(b) | |
data(b) = x | |
} |
This file contains hidden or 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
import scala.io.StdIn.readLine | |
object LetsPracticeBinary extends App { | |
def binaryToDecimal(input: String): Int = { | |
val tokens = input.toList | |
var total = 0 | |
var currPowerOfTwo = tokens.length - 1 | |
println("start", currPowerOfTwo) | |
for (token <- tokens) { |
This file contains hidden or 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
object Quick extends App { | |
def quicksort(data: Array[Int], begin: Int, end: Int): Unit = { | |
if(begin < end){ | |
val mid = partition(data, begin, end) | |
quicksort(data, begin, mid-1) | |
quicksort(data, mid+1, end) | |
} | |
} |
This file contains hidden or 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
// entry function (recursive) | |
function mergeSort(arr, copy, first, last){ | |
// set if not given | |
if(first === undefined && last === undefined && copy === undefined){ | |
first = 0; | |
last = arr.length - 1; | |
copy = _copy(arr); | |
} |