Skip to content

Instantly share code, notes, and snippets.

View sashang's full-sized avatar

sashang

  • https://tabcorp.com.au/
  • 05:26 (UTC +10:00)
  • LinkedIn in/sashang
View GitHub Profile
@sashang
sashang / median-tracking.cpp
Created November 7, 2017 02:49
median tracking
#include <iostream>
#include <algorithm>
#include <functional>
#include <queue>
using namespace std;
int main(int argc, char** argv)
{
priority_queue<int, vector<int>, function<bool(int,int)>>
@sashang
sashang / median.cpp
Created August 24, 2016 14:52
median tracking
if (min_heap.size() == max_heap.size())
{
if (u < max_heap.top())
{
max_heap.push(u);
total += max_heap.top();
}
else
{
min_heap.push(u);
defmodule Inversion do
def summarize(a, b, acc, list_acc) do
case {a, b} do
{[], []} -> {list_acc, acc}
{a, []} -> {list_acc ++ a, acc}
{[], b} -> {list_acc ++ b, acc}
{a,b} when hd(a) > hd(b) -> summarize(a, tl(b), length(a) + acc, list_acc ++ [hd(b)])
{a,b} when hd(a) <= hd(b) -> summarize(tl(a), b, acc, list_acc ++ [hd(a)])
end
defmodule Inversion do
def summarize(a, b, acc, list_acc) do
case {a, b} do
{[], []} -> {list_acc, acc}
{a, []} -> {Enum.reverse(a) ++ list_acc, acc}
{[], b} -> {Enum.revserse(b) ++ list_acc, acc}
{a,b} when hd(a) > hd(b) -> summarize(a, tl(b), length(a) + acc, [hd(b) | list_acc])
{a,b} when hd(a) <= hd(b) -> summarize(tl(a), b, acc, [hd(a) | list_acc])
end