Skip to content

Instantly share code, notes, and snippets.

View coderodde's full-sized avatar

Rodion Efremov coderodde

View GitHub Profile
@coderodde
coderodde / main.cpp
Last active July 10, 2017 15:45
CR: sorting int vector
#include <vector>
#include <chrono>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
template<typename RandomAccessIterator1, typename RandomAccessIterator2>
void merge_sort_impl(RandomAccessIterator1 source_begin,
def iterative_mergesort(arr):
range_length = len(arr)
if range_length < 2:
return
buf = [arr[i] for i in range(range_length)]
runs = range_length
merge_passes = get_number_of_merge_passes(runs)
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Funky {
private static final class Interval implements Comparable<Interval> {
int min;
int max;
@coderodde
coderodde / linked_list.c
Last active June 11, 2017 16:40
Natural merge sort for singly linked lists in C
#include "linked_list.h"
#include <stdlib.h>
#include <stdio.h>
void linked_list_init(linked_list_t* list)
{
list->head = NULL;
list->tail = NULL;
}
#include "numberbag.hpp"
#include <iostream>
int main() {
using coderodde::stat::number_bag;
using namespace std;
number_bag<float> bag;
bag.add(1.0);
from heapq import heappush, heappop
# This sort runs in O(n log k + k log k),
# which simplifies to O(n log k) whenever k = o(n)
# (k is sublinear in n).
def window_heapsort(a, k):
if k > len(a):
return sorted(a)
\documentclass[12pt]{article}
\usepackage{hyperref}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\author{Rodion ``rodde'' Efremov}
\title{Trying to get the gnuplot generated TikZ TeX to compile}
\maketitle
\begin{tikzpicture}[gnuplot]
@coderodde
coderodde / Main.java
Created February 1, 2017 07:57
CR string mergesort
import java.util.Arrays;
import java.util.Random;
public class Main {
private static void merge(Comparable[] a, Comparable[] aux, int low, int mid, int high) {
int i = low;
int j = mid;
@coderodde
coderodde / main.py
Created January 31, 2017 07:45
Serialize/deserialize a binary search tree.
class TreeNode:
def __init__(self, key):
self.key = key
self.left = None
self.right = None
def __eq__(self, other):
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>
#include <chrono>
#include <cstdint>
#include <random>
void mergeSort(std::vector<int>::iterator begin,
std::vector<int>::iterator end);