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 <iostream> | |
#include <cstdio> | |
#include <pthread.h> | |
#include <unistd.h> | |
typedef struct { | |
int thread_num; | |
} data_t; | |
void *task (void * data) { |
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 <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; |
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 <iostream> | |
#include <sstream> | |
struct entry { | |
std::string data; | |
int value; | |
entry * next; | |
}; | |
unsigned int hash(std::string s, int hash_size) { |
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 <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]) { |
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
// 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 | |
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
// dynamic programming longest common subsequence | |
#include <iostream> | |
#include <vector> | |
int main() { | |
const int N = 6; | |
int A[N] = {3, 2, 6, 4, 5, 1}; |
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
// 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) { |
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 <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) {} |
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 <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 |
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 "gliDump.h" | |
/* | |
***************************************************************************** | |
* * | |
* You shouldn't need to modify any of the functions below this point. * | |
* * | |
***************************************************************************** | |
*/ |