Skip to content

Instantly share code, notes, and snippets.

@vo
vo / pthreads.cpp
Created March 13, 2014 07:24
Stupid simple Pthread example for reference
#include <iostream>
#include <cstdio>
#include <pthread.h>
#include <unistd.h>
typedef struct {
int thread_num;
} data_t;
void *task (void * data) {
@vo
vo / qsort.c
Created March 13, 2014 21:42
Simple In-Place Quicksort in C (Just programming practice)
#include <cstdio>
#include <cstdlib>
#include <ctime>
void sort(int * a, size_t n) {
if (n < 2)
return;
int p = a[n/2];
int *l = a;
int *r = a + n-1;
@vo
vo / gist:9541767
Created March 14, 2014 03:41
Programming practice: Simple C++ Hash table
#include <iostream>
#include <sstream>
struct entry {
std::string data;
int value;
entry * next;
};
unsigned int hash(std::string s, int hash_size) {
@vo
vo / gist:9543136
Created March 14, 2014 06:51
Programming Practice: In-Place Heap Sort In C
#include <cstdio>
#include <ctime>
#include <cstdlib>
void make_heap(int * a, size_t n) {
for(int heapsize = 0; heapsize < n; ++heapsize) {
int n = heapsize;
while(n > 0) {
int p = (n-1) / 2;
if (a[n] > a[p]) {
@vo
vo / dijkstra.cpp
Last active August 29, 2015 13:57
Programming Practice: Dijkstra's Algorithm
// this version does not use a priority queue
#include <iostream>
int main() {
const int N = 9; // number of nodes
const int start = 0; // source
const int goal = 4; // destination
@vo
vo / gist:9907094
Created April 1, 2014 03:21
Programming Practice: Longest common subsequence
// dynamic programming longest common subsequence
#include <iostream>
#include <vector>
int main() {
const int N = 6;
int A[N] = {3, 2, 6, 4, 5, 1};
@vo
vo / findPaths.cpp
Created April 5, 2014 02:19
Programming Practice: Find paths that sum to a given value
// find all paths in a binary tree
// which sum to a given value
#include <iostream>
#include <vector>
struct Node {
int val;
Node * left, *right;
Node(int v) : val(v) {
@vo
vo / gist:be74826bb473831f30b1
Created May 5, 2014 15:45
Programming Practice: Basic Suffix Tree in C++
#include <iostream>
#include <cstring>
#include <climits>
using namespace std;
class index_list {
public:
int value;
index_list * next;
index_list(int i) : value(i), next(0) {}
@vo
vo / gist:054eae4d389ce4ad1f27
Created August 18, 2014 16:16
Programming Practice: Calculate and print the LCS
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// get the LCS from the matrix
string get_LCS(vector<vector<char> > & S, string & X, int i, int j) {
string result;
if (i == 0 || j == 0)
return result; // empty string
@vo
vo / gliDump.cpp
Created January 20, 2015 02:07
GL Dumping Screen
# include "gliDump.h"
/*
*****************************************************************************
* *
* You shouldn't need to modify any of the functions below this point. *
* *
*****************************************************************************
*/