Skip to content

Instantly share code, notes, and snippets.

View codingvideo's full-sized avatar
🎯
Focusing

codingvideo

🎯
Focusing
View GitHub Profile
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;
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
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);
// abstract
function makeCount(limit, abstractMethods){
let state = 0;
const _state = function(stateChange){
if(stateChange === undefined)
return state;
else
state = stateChange(state);
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
#include <limits>
using namespace std;
using Data = vector<int>;
using Words = vector<string>;
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);
}
};
@codingvideo
codingvideo / SwappableData.scala
Created February 4, 2020 22:02
Custom class for sorting data
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
}
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) {
@codingvideo
codingvideo / Quick.scala
Last active February 6, 2020 20:27
Quicksort in Scala
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)
}
}
// 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);
}