Skip to content

Instantly share code, notes, and snippets.

View tacigar's full-sized avatar
🏠
Working from home

tacigar tacigar

🏠
Working from home
View GitHub Profile
@tacigar
tacigar / QuickSort.cpp
Last active November 5, 2017 04:03
STLなクイックソートなり.
#include <algorithm>
#include <vector>
#include <iostream>
#include <list>
template <class BidirectionalIterator>
auto quickSort(BidirectionalIterator first, BidirectionalIterator last) -> void
{
auto l = first, r = std::prev(last);
while (l != r) {
@tacigar
tacigar / BinarySearch.cpp
Last active November 5, 2017 04:02
STLなバイナリサーチなり.
#include <vector>
#include <iterator>
#include <functional>
#include <cassert>
template <class RandomAccessIterator>
auto binarySearch(RandomAccessIterator first, RandomAccessIterator last,
typename std::iterator_traits<RandomAccessIterator>::value_type value) -> RandomAccessIterator
{
std::function<RandomAccessIterator(int, int)> _binarySearch = [&](int imin, int imax) -> RandomAccessIterator {
@tacigar
tacigar / quick_sort.ml
Last active November 5, 2017 04:02
クイックソートなり.
let rec partition p = function
| [] -> [], []
| hd :: tl ->
let ll, rl = partition p tl in
if p hd then
hd :: ll, rl
else
ll, hd :: rl
let rec quick_sort = function
@tacigar
tacigar / hashtbl.hpp
Last active November 5, 2017 04:01
ハッシュテーブルなり.
template <class V>
class hashtbl {
public:
static constexpr std::size_t hash_size = 800;
public:
hashtbl() : data_() {}
auto put(const std::string& key, const V& value) -> void {
auto h = hash(key);
@tacigar
tacigar / DijkstraAlgorithm.cpp
Last active November 5, 2017 04:00
ダイクストラアルゴリズムで二次元経路探索.
#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <vector>
class Vector2D {
public:
Vector2D() : x_(0), y_(0) {}
Vector2D(int x, int y) : x_(x), y_(y) {}
@tacigar
tacigar / heap_sort.c
Last active November 5, 2017 03:59
普通のヒープソートなり.
#include <stdio.h>
#include <stdlib.h>
void print_array(int * array, int size) {
int i = 0;
printf("{ ");
while (1) {
printf("%d", array[i]);
if (++i >= size) {
printf("}\n");
@tacigar
tacigar / insert_sort.c
Last active November 5, 2017 03:59
普通の挿入ソートなり.
#include <stdio.h>
void print_array(int * array, int size) {
int i = 0;
printf("{ ");
while (1) {
printf("%d", array[i]);
if (++i >= size) {
printf("}\n");
break;
@tacigar
tacigar / merge_sort.c
Last active November 5, 2017 03:58
普通のマージソートなり.
#include <stdio.h>
#include <stdlib.h>
void print_array(int * array, int size) {
int i = 0;
printf("{ ");
while (1) {
printf("%d", array[i]);
if (++i >= size) {
printf("}\n");
@tacigar
tacigar / quick_sort.c
Last active November 5, 2017 03:58
普通のクイックソートなり.
#include <stdio.h>
void print_array(int * array, int size) {
int i = 0;
printf("{ ");
while (1) {
printf("%d", array[i]);
if (++i >= size) {
printf("}\n");
break;
@tacigar
tacigar / l_geom.c
Last active November 5, 2017 03:56
Lua C APIを触ってみた.
#include <lua5.2/lua.h>
#include <lua5.2/lualib.h>
#include <lua5.2/lauxlib.h>
#define POINT2D_CLASS "Point2D"
typedef struct point2d { int x; int y; } point2d;
static void create_point2d(lua_State *L, int x, int y) {
point2d* pnt = (point2d *)lua_newuserdata(L, sizeof(point2d));
luaL_getmetatable(L, POINT2D_CLASS);