This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
OlderNewer