text stringlengths 1 24.5M |
|---|
/*******************************************************************************
* ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* K-MEANS:
* http://en.wikipedia.org/wiki/K-means_clustering
*
* First Contributo... |
/*******************************************************************************
* ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* KNUTH-MORRIS-PRATT ALGORITHMS
*
* Features:
* Complexity is O(n + k), where n is ... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* Kruskal'S ALGORITHM -- MINIMUM SPANNING TREE
*
* Features:
*
* Kruskal's algorithm is a greedy ... |
/*******************************************************************************
*
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* LCA Finding using Binary Lifting and Dynamic Programming
*
* Features:
* 1. Answers Query about LCA of two nodes in O(log N)
* ... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* LARGEST COMMON SEQUENCE
*
* http://en.wikipedia.org/wiki/Longest_common_s... |
/*******************************************************************************
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* Least Recently Used (LRU):
* discards the least recently used items first. This algorithm requires
* keepin... |
/*******************************************************************************
* ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* MAXIMUM SUBARRAY
*
* In computer science, the maximum subarray problem is the task... |
/*
**********************************************************************
** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
** **
** License to copy and use this software is granted provided that **
** it is identified as the "... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* MERGE SORT
*
* Features:
* This is divide and conquer algorithm. This ... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* PALINDROMES
*
* WORDS LIKE:
* RACECAR DEED LEVEL PIP
* ROTOR CIVIC PO... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* PERFECT HASH
*
* http://en.wikipedia.org/wiki/Perfect_hash
*
********... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* PRIME TEST FUNCTION
*
* http://en.wikipedia.org/wiki/Primality_test
* ht... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* PRIM'S ALGORITHM -- MINIMUM SPANNING TREE
*
* Features:
*
* Prim's al... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* PRIORITY QUEUE
*
* Features:
* 1. A queue with prioity implemented in d... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
* QUEUE
*
* Features:
* 1. Queue with capcity
*
* http://en.wikipedia.org... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* QUICKSORT
*
* Features:
* 1. sort array in O(nlogn) time.
* 2. most gen... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* RADIX SORT
*
* Features:
* 1. sort unsigned 32-bit array in O(n) time... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* RANDOM NUMBER GENERATOR
*
* http://en.wikipedia.org/wiki/Pseudorandom_num... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* Quickselect
* In computer science, a quickselect is a selection algorith... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* RED-BLACK TREE
*
* Features:
* 1. balanced tree
* 2. O(logn) lookup per... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* RED-BLACK TREE DEFINITON
*
* Features:
* 1. balanced tree
* 2. O(logn) ... |
/*
* Relabel-To-Front algorithm
*
* Features: Relabel-to-front maxflow algorithm's upper bound is O(V3), faster than Edmonds-Karp in theory. Relabel-to-front algorithm is a kind of push-relabel algorithm using FIFO heuristic.
* But the funny thing is, in practice, this method is much slower than Edmonds-Karp.
* Yo... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* STRONGLY CONNECTED COMPONENT
*
* In the mathematical theory of directed g... |
/*******************************************************************************
* ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* SELECTION SORT
*
* In computer science, selection sort is a sorting algorithm, spe... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* SHA-1
*
* Description:
* This file implements the Secure Hashing St... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* SHELL SORT
*
* 1. sort array in O(n^(3/2)) time.
*
* https://en.wiki... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* FISHER YATES'S SHUFFLE
*
* Features:
* 1. shuffle list in O(n) time.
*... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* SIMHASH FUNCTIONS
*
* http://matpalm.com/resemblance/simhash/
* http://e... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* SKIP LIST
*
* http://en.wikipedia.org/wiki/Skip_list
*
****************... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* SELF ORGANIZED LINKED-LIST
*
* Features:
* 1. Implementation of MTF (mov... |
#ifndef _SORT_H_
#define _SORT_H_
#include <iostream>
#include <vector>
using namespace std;
namespace alg{
template<typename T>
class SortClass{
public:
SortClass(vector<T>& sort_list,bool(*comp)(T,T),void(*_swap)(T&,T&)){
m_sort_list=&sort_list;
compre=comp;
swap=_swap;
}
~SortClass(){
... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* STACK
*
* Features:
* 1. Stack with capcity
*
* http://en.wikipedia.... |
/*******************************************************************************
* ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* SUFFIX ARRAY
*
* Features:
* suffix array can sort all the suffixs in time compl... |
#include <string>
//#include <tr1/unordered_map>
#include <limits>
#include <map>
#include <vector>
#include <iostream>
#include <stdexcept>
using std::vector;
using std::string;
using std::map;
using std::make_pair;
using std::cout;
using std::endl;
using std::out_of_range;
using std::ostream;
//typedef tr1::unordere... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* Trie (Prefix tree)
*
* http://en.wikipedia.org/wiki/Trie
***************... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* UNDIRECTED GRAPH
*
* Features:
* 1. Adjacency List Implementation
*
* ... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* UNIVERSAL HASH FUNCTION
*
* http://en.wikipedia.org/wiki/Universal_hash
... |
/*******************************************************************************
* DANIEL'S ALGORITHM IMPLEMENTAIONS
*
* /\ | _ _ ._ o _|_ |_ ._ _ _
* /--\ | (_| (_) | | |_ | | | | | _>
* _|
*
* CHINESE WORD SEGMENTATION
*
* Features:
* 1. based on Hidden Markov Mode... |
#ifndef ALGO_ALGVS_H__
#define ALGO_ALGVS_H__
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define __func__ __FUNCTION__
#define strtok_r strtok_s
#if _MSC_VER <= 1800
#define ALG_VLA_NOT_SUPPORTED
#endif
#define typeof decltype
#endif//_MSC_VER
#endif//ALGO_ALGVS_H__ |
#ifdef _MSC_VER
#endif |
#include <stdio.h>
#include <8queen.h>
int main(void) {
alg::Queen8 q;
q.solve();
}
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "astar.h"
#define N 128
#define MARK 0xEE
int main(void)
{
using namespace alg;
Array2D<unsigned char> grid(N,N);
grid.clear(0);
srand(time(NULL));
int i,j;
for (i=N/4;i<=3*N/4;i++) {
grid(3*N/4,i) = AStar::WALL;
grid(i,3*N/4) = AStar::WA... |
#include <iostream>
#include "avl.h"
using namespace std;
using namespace alg;
const unsigned N = 4096*32;
const unsigned N_ELEMS_TO_REMOVE = N-128; // Must be between 0 and N-1
template <typename T>
void printTreeStatus(const AVL<T> &t) {
cout << "----------------------------------------" << endl;
if (t.is... |
#include <iostream>
#include "base64.h"
#include <string.h>
using namespace std;
int main() {
const char *s = "Matthew 7:24-27 Therefore everyone who hears these words of mine and puts them into practice is like a wise man who built his house on the rock. 25 The rain came down, the streams rose, and the winds blew a... |
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory>
#include "directed_graph.h"
#include "bellman_ford.h"
using namespace alg;
int main(void)
{
srand(time(NULL));
int NVERTEX = 10;
DirectedGraph * g = DirectedGraph::randgraph(NVERTEX);
g->printdot();
BellmanFord bf(*g)... |
#include <stdio.h>
#include <generic.h>
#include <time.h>
#include "shuffle.h"
#include "binary_search_tree.h"
using namespace alg;
int main()
{
const int MAX_ELEMENTS = 10;
int key[MAX_ELEMENTS];
int value[MAX_ELEMENTS];
BST<int, int> t;
int i = 0;
srand(time(NULL));
// generate random numbers and fill them... |
#include <stdio.h>
#include <stdlib.h>
#include "bitset.h"
using namespace alg;
int main(void)
{
int MAXELEMENT = 100;
BitSet bs(MAXELEMENT);
int i;
printf("\nsetting bits: \n");
for (i=0;i < MAXELEMENT;i++) {
int v = rand()%2;
if (v==0) {
bs.set(i);
printf("1");
}
else printf("0");
}
printf(... |
#include <stdio.h>
#include <stdlib.h>
#include "bloom_filter.h"
int main(void)
{
using namespace alg;
const char * strs[] = {
"purple_lover_04@msn.com",
"hollie.smith@yahoo.com",
"hollister.susan @gmail.com",
"alexptre@gmail.com",
"cfo@sjtu-edp.cn",
"abms@n23h22.rev.sprintdatacenter.pl",
"admin... |
#include <stdio.h>
#include "btree.h"
using namespace alg;
int main(void) {
BTree x("./btree.dat");
int32_t i;
for (i=0;i<1000;i++) {
x.Insert(i);
printf("insert %d\n", i);
BTree::Res r = x.Search(i);
if (r.idx == -1) {
printf("key[%d] insert failed\n", i);
}
}
for (i=0;i<1000;i++) {
x.DeleteKe... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "generic.h"
#include "bubble_sort.h"
using namespace alg;
int main (int argc, char const *argv[]) {
const int MAX_ELEMENTS = 10;
int list[MAX_ELEMENTS];
for(int i = 0; i < MAX_ELEMENTS; i++ ){
list[i] = rand()%100;
}
printf("The list before sor... |
#include "dictionary.h"
#include "hash_table.h"
#include "random.h"
#include <chrono>
using namespace alg;
using namespace std::chrono;
int main(void) {
Dictionary<int, int> dict;
dict.Add(0, 1);
dict.Add(1, 2);
dict.Add(5, 2);
dict.Add(3, 3);
dict.Remove(5);
dict.AddOrUpdate(3, 4);
for (auto x : dict)
{... |
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory>
#include "directed_graph.h"
#include "dijkstra.h"
using namespace alg;
int main(void)
{
using namespace alg;
srand(time(NULL));
int NVERTEX = 10;
std::auto_ptr<DirectedGraph> g(DirectedGraph::randgraph(NVERTEX));
g->p... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "directed_graph.h"
using namespace alg;
int main()
{
srand(time(NULL));
int NVERTEX = 20;
DirectedGraph * g = DirectedGraph::randgraph(NVERTEX);
g->printdot();
printf("Random Delete Vertex:\n");
// random delete vertex
int i;
for(i=0;i<NVERT... |
#include <disjoint-set.h>
#include <stdio.h>
#include <iostream>
int main(void) {
alg::Set<int> s1;
alg::Set<int> s2;
alg::MakeSet(&s1);
alg::MakeSet(&s2);
printf("before:\n");
std::cout<< alg::FindSet(&s1) << std::endl;
std::cout<< alg::FindSet(&s2) << std::endl;
printf("after:\n");
alg::Union(&s1, &s2);
... |
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include <stdlib.h> /* rand() */
#include "dos_tree.h"
using namespace alg;
int main(void)
{
DosTree t;
t.print();
srand(time(NULL));
int MAXELEMENT = 50;
int i;
for(i=0; i<MAXELEMENT; i++) {
int key = rand() % 1000;
printf("Insertin... |
#include <stdio.h>
#include <stdlib.h>
#include "double_linked_list.h"
#include "sol.h"
using namespace alg;
struct DemoNode{
int key;
struct list_head list;
};
int main()
{
struct list_head head, head2;
INIT_LIST_HEAD(&head);
INIT_LIST_HEAD(&head2);
printf("list_add[head#1]:\n");
int i;
struct DemoNode * ... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "edmonds_karp.h"
using namespace alg;
int main(void)
{
using namespace alg;
srand(time(NULL));
int NVERTEX = 6;
DirectedGraph * g = DirectedGraph::randgraph(NVERTEX);
g->printdot();
printf("finding Maximal Flow from 0 to 5: \n");
EdmondsKarp ek... |
#include <cstdio>
#include "fenwick_tree.h"
int main()
{
Fenwick ft(5);
ft.update(2, 1);
ft.update(4, 10);
printf("%d\n", ft.rsq(1));
ft.update(1, 5);
printf("%d\n", ft.rsq(1));
return 0;
} |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "fib-heap.h"
int main(void) {
srand(time(NULL));
alg::FibHeap<int32_t, int32_t> heap;
int32_t i;
for (i=0;i<10;i++) {
heap.Insert(rand(), i);
}
for (i=0;i<10;i++) {
alg::FibHeap<int32_t, int32_t>::Node n;
n = heap.ExtractMin();
if (n!= N... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "undirected_graph.h"
/**
* randomly generate a graph, for test purpose
*/
struct Graph * undirected_graph_rand(int nvertex)
{
struct Graph * g = undirected_graph_create();
int i;
for(i=0;i<nvertex;i++) {
undirected_graph_add_vertex(g, i);
... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "graph_search.h"
#include "directed_graph.h"
using namespace alg;
int main()
{
using namespace alg;
srand(time(NULL));
int NVERTEX = 10;
Graph * g = DirectedGraph::randgraph(NVERTEX);
g->printdot();
printf("breadth first search: \n");
BFS(*g,... |
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include "hash_multi.h"
using namespace alg;
int main()
{
const int MAX_ELEMENTS = 50;
srand(time(NULL));
struct MultiHash * ht = multi_hash_init(MAX_ELEMENTS);
printf("required space for storage is %d\n", multi_hash_table_size(ht));
... |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hash_string.h"
using namespace alg;
int main(void)
{
const char * strs[] = {
"",
"a",
"foobar",
"first string",
"second string",
"third string",
"this is the fourth string",
"and finally this is the fifth string"
};
prin... |
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include "hash_table.h"
using namespace alg;
int main()
{
const int MAX_ELEMENTS = 50;
srand(time(NULL));
HashTable<uint32_t, uint32_t> ht(MAX_ELEMENTS);
printf("Hash Table Demo: \n");
int i;
for(i = 0; i < MAX_ELEMENTS; i++ ){
int... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "heap.h"
int main()
{
using namespace alg;
int MAXELEMENTS=10;
Heap<int> heap(MAXELEMENTS);
int i;
srand(time(NULL));
for (i=0;i < MAXELEMENTS; i++) {
heap.push(100-i, i);
printf("push: key:%d->value:%d\n", 100-i, i);
}
heap.print_heap();
... |
#include <stdio.h>
#include <stdlib.h>
#include "huffman.h"
#define STR "Huffman coding uses a specific method for choosing the representation for each symbol, resulting in a prefix code (sometimes called 'prefix-free codes', that is, the bit string representing some particular symbol is never a prefix of the bit stri... |
#include <stdio.h>
#include "imath.h"
int main() {
for (int i=10000;i<10100;i++) {
for (int j=100000;j<100010;j++) {
printf("%d^%d mod %d = %d\n", i,j,997, alg::Exp(i, j, 997));
}
}
unsigned int n = 104;
printf("%x has %d zeros on the right side\n", n, alg::ZerosR(n));
}
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "generic.h"
#include "insertion_sort.h"
using namespace alg;
int main()
{
const int MAX_ELEMENTS = 10;
int list[MAX_ELEMENTS];
int i = 0;
srand(time(NULL));
// generate random numbers and fill them to the list
for(i = 0; i < MAX_ELEMENTS; ... |
#include <stdio.h>
#include <stdlib.h>
#include "integer.h"
using namespace alg;
int main(void)
{
Integer a = Integer::from_string("1234567890");
Integer b = Integer::from_string("9876543210");
Integer c = a+b;
printf("%s + %s = %s\n", a.to_string(), b.to_string(), c.to_string());
printf("%s - %s = %s\n", a.to_... |
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include <stdlib.h> /* rand() */
#include "interval_tree.h"
using namespace alg;
int main() {
int i;
IntervalTree t;
t.print();
srand(time(NULL));
int MAXELEMENT = 50;
for(i=0; i<MAXELEMENT; i++) {
int low = rand() % 100;
int high = ... |
#include <stdio.h>
#include <stdlib.h>
#include "k-means.h"
using namespace alg;
int main()
{
double data[] = {
0.0, 0.2, 0.4,
0.3, 0.2, 0.4,
0.4, 0.2, 0.4,
0.5, 0.2, 0.4,
5.0, 5.2, 8.4,
6.0, 5.2, 7.4,
4.0, 5.2, 4.4,
10.3, 10.4, 10.5,
10.1, 10... |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "kmp.h"
using namespace alg;
int main(void)
{
srand(time(NULL));
char * S = (char*)malloc(1001);
char * W = (char*)malloc(5);
memset(S,0, 1001);
memset(W,0, 5);
// random genrate a pattern for A, G, C,T
const char P[] = {'A'... |
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "undirected_graph.h"
#include "kruskal_mst.h"
using namespace alg;
int main(void)
{
using namespace alg;
srand(time(NULL));
int NVERTEX = 10;
UndirectedGraph * g = UndirectedGraph::randgraph(NVERTEX);
g->printdot();
printf("Gen... |
#include "LCA.h"
#include <cstdio>
#include <vector>
#include <iostream>
/**
*Constructor is initialized with a Adjacency List that
*describe a tree and If It doesn't describe a tree it asserts failure.
*/
LCA::LCA(std::vector< std::pair<int,int> > edges): _numberOfNodes(edges.size() + 1), _maxLog(getMaxLog())
{
/... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "lcs.h"
#include "stack.h"
#define printlistC(list,n) \
do { \
int list_counter_; \
for(list_counter_=0;list_counter_<n;list_counter_++) \
printf("%c\t ",list[list_counter_]); \
printf("\n"); \
} while(0)
int main(void)
{
using namespace alg;
co... |
#include <iostream>
#include "LRU_cache.h"
using namespace std;
using namespace alg;
int main() {
LRUCache<string,string> Cache(5);
Cache.putValue("key1","value1");
Cache.putValue("key2","value2");
Cache.putValue("key3","value3");
Cache.putValue("key4","value4");
Cache.putValue("key5","value5");
Cache.p... |
#include <stdio.h>
#include "max_subarray.h"
using namespace alg;
int main() {
int arr[] = {13,-3,-25,20,-3,-16,-23,18,20,-7,12,-5,-22,15,-4,7};
int arr2[] = {1,-1,-2,-3,-4};
int begin;
int end;
int i;
printf("the array:\n");
for (i=0;i<int(sizeof(arr)/sizeof(int));i++) {
printf("%d\t", arr[i]);
}
printf... |
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include <string.h>
#include "md5.h"
/* Prints message digest buffer in mdContext as 32 hexadecimal digits.
Order is from low-order byte to high-order byte of digest.
Each byte is printed with high-order hexadecimal digit first.
*/... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "generic.h"
#include "merge_sort.h"
using namespace alg;
int main()
{
const int MAX_ELEMENTS = 20;
int list[MAX_ELEMENTS];
int i = 0;
// generate random numbers and fill them to the list
for(i = 0; i < MAX_ELEMENTS; i++ ){
list[i] = rand()%10... |
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include "imath.h"
#include "prime.h"
using namespace alg;
int main()
{
uint32_t k[KLEN];
int i;
int m;
for(i=9;;i+=2)
{
if (is_prime(i))
{
m=i;
break;
}
}
srand(time(NULL));
int key = rand()%1000;
m_based(key, m , k)... |
#include "palindrome.h"
#include <stdio.h>
int main() {
alg::palindrome("banana");
alg::palindrome("abba");
alg::palindrome("aaaaa");
}
|
/*******************************************
* DANIEL'S PRIVATE ALGORITHM IMPLEMENTAIONS
* Perfect Hashing
* Features:
* 1. based on Universal Hashing
* 2. O(1) query
* 3. Some applications naturally have !!!STATIC SETS OF KEYS!!!:
consider the set of reserved words in a programming language,
or the set of... |
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
typedef uint32_t pint;
typedef uint64_t xint;
typedef unsigned int uint;
#define PRIuPINT PRIu32 /* printf macro for pint */
#define PRIuXINT PRIu64 /* printf macro for xint */
#define MAX_FACTORS 63 /* because 2^6... |
#include <stdio.h>
#include <prime.h>
#include <time.h>
using namespace alg;
int main()
{
unsigned i;
int miller = 0;
time_t t1 = time(NULL);
int prime;
for (i = 1000000000; i<1001000000; i++) {
if (miller_rabin_test(i)) {
miller++;
prime=i;
}
}
time_t t2 = time(NULL);
printf("found %d miller-primes... |
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "undirected_graph.h"
#include "prim_mst.h"
int main(void)
{
using namespace alg;
srand(time(NULL));
int NVERTEX = 10;
alg::UndirectedGraph * g = alg::UndirectedGraph::randgraph(NVERTEX);
g->printdot();
printf("Generating Prim'... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "priority_queue.h"
int main(void)
{
using namespace alg;
PQ<int> pq;
srand(time(NULL));
int MAXELEMENT = 20;
int i;
for (i=0;i<MAXELEMENT;i++) {
int pri = rand()%1000;
pq.queue(i, pri);
printf("queueing: value:%u-> pri: %d\n", i, pri);
... |
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "queue.h"
int main()
{
using alg::Queue;
const int MAXELEMENT = 20;
Queue<int> Q(MAXELEMENT);
int i;
for (i=0;i<MAXELEMENT;i++) {
int value = rand()%1000;
printf("queuing %d\n", value);
Q.enqueue(value);
}
printf("queue count:%u\n", Q... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "generic.h"
#include "quick_sort.h"
int main()
{
RANDOM_INIT();
using namespace alg;
const int MAX_ELEMENTS = 10;
int list[MAX_ELEMENTS];
int i = 0;
srand(time(NULL));
// generate random numbers and fill them to the list
for(i = 0; i < MAX_EL... |
#include <stdio.h>
#include <stdint.h>
#include <time.h>
#include "generic.h"
#include "radix_sort.h"
int main()
{
using namespace alg;
const int MAX_ELEMENTS = 10;
uint32_t list[MAX_ELEMENTS];
int i = 0;
srand(time(NULL));
// generate random numbers and fill them to the list
for(i = 0; i < MAX_ELEMENTS; i++ ... |
#include <iostream>
#include "random.h"
int main(void) {
std::cout <<"generate random numbers\n";
for (int i=0;i<100;i++) {
std::cout<<alg::LCG()<<"\n";
}
}
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "generic.h"
#include "random_select.h"
int main()
{
RANDOM_INIT();
using namespace alg;
const int MAX_ELEMENTS = 10;
int list[MAX_ELEMENTS];
int i = 0;
// generate numbers and fill them to the list
for(i = 0; i < MAX_ELEMENTS; i++ ){
list... |
/* Copyright (c) 2013 the authors listed at the following URL, and/or
the authors of referenced articles or incorporated external code:
http://en.literateprograms.org/Red-black_tree_(C)?action=history&offset=20120524204657
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software an... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "edmonds_karp.h"
#include "relabel_to_front.h"
using namespace alg;
int main(void)
{
using namespace alg;
srand(time(NULL));
int NVERTEX = 300;
clock_t ek_start, ek_end, pr_start, pr_end;
DirectedGraph * g = DirectedGraph::randgraph(NVERTEX);
//... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "directed_graph.h"
#include "graph_search.h"
#include "scc.h"
using namespace alg;
int main()
{
using namespace alg;
srand(time(NULL));
DirectedGraph * g = new DirectedGraph;
// construct 3 islands
int32_t i;
for (i=0;i<9;i++) {
g->add_vertex... |
#include <stdio.h>
#include "selection_sort.h"
template<typename T>
static void printlist(T & list,int count) {
int i;
for(i=0;i<count;i++)
printf("%d\t ",list[i]);
printf("\n");
}
int main (int argc, char const *argv[]) {
const int MAX_ELEMENTS = 10;
int list[MAX_ELEMENTS];
for(int i = 0; i < MAX_ELEMENTS; ... |
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sha1.h"
#define TESTA "abc\n"
int main(void)
{
SHA1Context sha;
sha1_reset(&sha);
sha1_input(&sha, (const unsigned char *) TESTA, strlen(TESTA));
if (sha1_final(&sha))
{
printf("sha %s --> ", TESTA);
int i;
for(i = 0; ... |
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "generic.h"
#include "shell_sort.h"
using namespace alg;
int main()
{
const int MAX_ELEMENTS = 10;
int list[MAX_ELEMENTS];
int i = 0;
srand(time(NULL));
// generate random numbers and fill them to the list
for(i = 0; i < MAX_ELEMENTS; i++ ... |
/*******************************************
* DANIEL'S PRIVATE ALGORITHM IMPLEMENTAIONS
* Fisher Yates's shuffle algorithm
* Features:
* 1. shuffle list in O(n) time.
*******************************************/
#include <stdio.h>
#include <stdlib.h>
#include "generic.h"
#include "shuffle.h"
using namespace alg... |
#include <stdio.h>
#include <string.h>
#include "simhash.h"
using namespace alg;
void addsentence(char * str, SimHash &h);
int main(void) {
char strA[] = {"the cat sat on the mat"};
char strB[] = {"the cat sat on a mat"};
char strC[] = {"we all scream for ice cream"};
printf("%s\n", strA);
printf("%s\n", strB);
... |
#include <stdio.h>
#include "skiplist.h"
using namespace alg;
int main()
{
SkipList<int, int> ss;
const int MAX_ELEMENTS = 20;
int i = 0;
srand(time(NULL));
for(i = 0; i < MAX_ELEMENTS; i++ ){
ss.insert(i, rand()%100);
}
printf("The skip list :\n");
ss.print();
printf("Random get keys :\n");
for(i ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.