Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View santa4nt's full-sized avatar
💭
😬

Santoso santa4nt

💭
😬
  • Los Angeles, CA
View GitHub Profile
@santa4nt
santa4nt / HeapSort.java
Last active August 29, 2015 14:27
HeapSort implementations.
public class HeapSort {
private static int parent(int idx) {
return (idx - 1) / 2;
}
private static int left(int idx) {
return 2 * idx + 1;
}
@santa4nt
santa4nt / traversal.cc
Last active August 29, 2015 14:27
Binary tree traversal algorithms, without recursion.
#include <stack>
#include <vector>
#include <memory>
#include <functional>
#include <iostream>
#include "tree.hpp"
using namespace std;
@santa4nt
santa4nt / toposort-ex.cc
Last active August 29, 2015 14:27
Topological Sort on a DAG
#include <set>
#include <stack>
#include <vector>
#include <memory>
#include <iostream>
#include <exception>
#include <cassert>
using namespace std;
@santa4nt
santa4nt / inorder-rank.cpp
Last active August 29, 2015 14:26
In-order traversal on a BST without recursion.
#include <stack>
#include <vector>
#include <memory>
#include <functional>
#include <exception>
#include <iostream>
#include <cassert>
template <typename T>
@santa4nt
santa4nt / InOrder.java
Last active August 29, 2015 14:26
In-order traversal on a BST without recursion.
import java.util.Stack;
public class InOrder {
public static class TreeNode<T extends Comparable<T>> {
public T data;
public TreeNode<T> left, right;
public TreeNode(T data) {
this(data, null, null);
@santa4nt
santa4nt / Makefile
Last active August 29, 2015 14:26
Various implementations of string manipulations in C++.
CC = g++
CFLAGS = -std=c++11 -Wall -g
LFLAGS = -lboost_unit_test_framework
DEFINES = -D_DEBUG
TARGET = stringmisc-test
all: $(TARGET)
stringmisc-test: stringmisc.o stringmisc-test.o
#include "LoGrid.hpp"
#if _DEBUG
void PrintLoGrid(const LoGrid &g)
{
// TODO
}
#endif
@santa4nt
santa4nt / logrid.py
Last active August 29, 2015 14:25
A Simple LightsOut Grid in Python.
from cStringIO import StringIO
class LoGrid(object):
def __init__(self, dim, init_state=[]):
"""Set up a square matrix of `dim` by `dim` size.
Optionally, provide an initial state in the form of a linear boolean
array (list) of length `dim` squared.
@santa4nt
santa4nt / Makefile
Created June 2, 2015 18:11
Sample SFML app (Linux-based)
CXX = g++ -std=c++11
LIBS = -lsfml-graphics -lsfml-window -lsfml-system
all: sample-sfml-app
%.o: %.cpp
$(CXX) -c $< -o $@
%.o: %.hpp
$(CXX) -c $< -o $@
@santa4nt
santa4nt / HelloJNI.java
Last active December 19, 2023 22:50
Sample JNI/C++ HelloWorld
public class HelloJNI {
static {
System.loadLibrary("hello"); // loads libhello.so
}
private native void sayHello(String name);
public static void main(String[] args) {
new HelloJNI().sayHello("Dave");
}