Skip to content

Instantly share code, notes, and snippets.

View alexnoz's full-sized avatar
💡

Alex Nozdriukhin alexnoz

💡
  • Third Stone from the Sun
View GitHub Profile
@alexnoz
alexnoz / toposort.cpp
Created September 4, 2018 20:58
Topological sort of a DAG using depth-first search
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using edges_t = vector<int>;
using graph_t = vector<edges_t>;
template <typename T>
@alexnoz
alexnoz / avl.cpp
Last active September 4, 2018 12:05
An AVL tree implementation in C++
#include <iostream>
#include <climits>
#include <queue>
#include "avl.h"
namespace {
int max(int a, int b) {
return a > b ? a : b;
}
@alexnoz
alexnoz / levenshtein-distance.cpp
Created August 30, 2018 15:27
Levenshtein distance calculation using Wagner–Fischer algorithm
#include <iostream>
#include <string>
#include <vector>
#include <cstdarg>
#include <climits>
using namespace std;
int min(int count, ...) {
int min = INT_MAX;
@alexnoz
alexnoz / mwb.cpp
Created August 29, 2018 18:23
Minimum word break problem in C++
#include <iostream>
#include <queue>
#include <string>
#include <map>
using namespace std;
struct Trie;
using trie_t = map<char, Trie*>;
@alexnoz
alexnoz / djkstra.cpp
Created August 28, 2018 22:21
Djkstra algorithm in C++
#include <iostream>
#include <vector>
#include <array>
#include <climits> // INT_MAX
#include <algorithm> // find
using namespace std;
using edges_t = vector<array<int, 2>>;
using graph_t = vector<edges_t>;
@alexnoz
alexnoz / bellman-ford.cpp
Created August 28, 2018 19:13
Bellman-Ford algorithm in C++
#include <iostream>
#include <vector>
#include <array>
#include <climits> // INT_MAX
using namespace std;
struct Node {
int p = -1;
int d = INT_MAX;
@alexnoz
alexnoz / heapsort.cpp
Created August 20, 2018 10:29
Heapsort c++
#include <iostream>
void swap (int* arr, int i, int j) {
const int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
void heapify (int* arr, int max, int root) {
const int left = root * 2;
@alexnoz
alexnoz / mergesort.cpp
Created August 18, 2018 16:28
Mergesort c++
#include <iostream>
void merge(const int l, const int m, const int h, int* arr) {
const int len = h - l + 1;
int* const temp = new int[len];
int i = l;
int j = m + 1;
int k = 0;
@alexnoz
alexnoz / rename-chunk-plugin.js
Created July 17, 2018 17:47
A webpack plugin for renaming individual chunks
const id = 'RenameChunkPlugin'
module.exports = class RenameChunkPlugin {
constructor (filenameMap) {
this.filenameMap = filenameMap
}
apply (compiler) {
compiler.hooks.thisCompilation.tap(id, compilation => {
compilation.hooks.optimizeChunkModules.tap(id, chunks => {
function createElement (name, attrs, ...children) {
name = name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase()
const $el = document.createElement(name)
if (attrs) {
for (const [attr, val] of Object.entries(attrs))
$el.setAttribute(attr, val)
}