摘要: BoostGraph Library使用泛型的思想,完整的编写了图中的各类算法。比如广搜,深搜,最短路径等等1.创建一个图1.1图的表示图可以有邻接矩阵和邻接表来表示,而在BGL中,则使用adjacency_list和adjacency_matrix来表示,adjacency_list使用邻接表来存储一个图,而adjacency_matrix使用邻接矩阵来存储,分别适用于点比较稀疏的图和点比较密集的图。使用邻接表时可以使用以下定义:1 typedef adjacency_list<listS, vecS, directedS> file_dep_graph;其中listS表示将每个 阅读全文
posted @ 2012-02-22 10:43 Richard Zhong 阅读(2896) 评论(2) 推荐(0) 编辑
摘要: 1 #include <iostream> 2 3 using std::set; 4 using std::cout; 5 using std::endl; 6 #define NODENUM 5000 7 8 struct Node{ 9 int low;10 int high;11 int subNodeNum;12 };13 14 Node node_array[NODENUM];15 16 void build(int l, int r, int root_index)17 {18 Node tmpNode;19 tmpNode.low ... 阅读全文
posted @ 2011-12-27 08:53 Richard Zhong 阅读(442) 评论(0) 推荐(2) 编辑
摘要: #include <stdio.h>#include <stdlib.h>#include <string.h>int maxPrefix(const char* str1, const char* str2);intstate_transport(const char* p, const int n, const int m, char a){ char pk[n+2]; strncpy(pk, p, n); pk[n]=a; pk[n+1]='\0'; return maxPrefix(pk, p);}intmaxPrefix(const 阅读全文
posted @ 2011-10-12 16:21 Richard Zhong 阅读(397) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <stdlib.h>#include <iostream>using namespace std;template <class T>struct Entry;template <class T>struct Link_head{ Entry<T>* next; int size;};template <class T>struct Entry{ Entry<T>* next; T* element;};template <class T& 阅读全文
posted @ 2011-09-01 07:53 Richard Zhong 阅读(339) 评论(0) 推荐(0) 编辑
摘要: 程序:1:式子(就是代码行,呵呵)2:程序的终止程序是由式子并排组成的。式子和式子之间使用分号或者换行来区分(译者注:如果你想把两行式子写在同一行中间就用分号隔开,如果分开在两行就无需分号)。但是如果使用反斜杠(\)的话,表示下一行继续接着上一行。例:print "hello world!\n"(一如既往的Hello world)式子:例: true (1+2)*3 foo() if test then ok else ng endRuby的式子中充斥着,变量和常量,各种各样的直接量,运算和代入,if和while这种控制结构方法的调用,类和方法的定义等等。式子可以通过括号来 阅读全文
posted @ 2011-08-24 14:09 Richard Zhong 阅读(192) 评论(0) 推荐(0) 编辑
摘要: Ruby的字句构造:1:变量2:注释3:嵌入文档4:保留字Ruby目前的实现使用的是ASCII字符集。能够识别大写和小写字母。除了变量和一部分直接量的中间,可以在任意地方加入空格和注释,空格、制表符、垂直制表符、backspace、回车符、换行符、换页符。当代码换行继续写的时候,除了空格,其它一律解释为单独语句。(译者注:即在代码写的太长,想换行时中间只能加空格,否则会出错)<1>变量:例: foobar ruby_is_simpleRuby的变量名可以使用字母或者下划线开始和结束。变量名称的长度没有限制。<2>注释:例: #this is a comment line 阅读全文
posted @ 2011-08-24 13:04 Richard Zhong 阅读(545) 评论(0) 推荐(0) 编辑
摘要: 大家知道,STL中的map底层是用红黑树实现的,其泛型原型如下:template <class _Key, class _Tp, class _Compare, class _Alloc>class map { ...... }其中_Key表示比较的键(key),_Tp表示值(value),_Compare表示比较方式,_Alloc表示内存分配器。一般我们在写map的时候总是类似于写出如下代码:map<int, char*>* my_map = new map<int, char*>;表示键为int类型,值为字符串类型。这里之所以不对_Compare和_Al 阅读全文
posted @ 2011-08-12 09:08 Richard Zhong 阅读(9799) 评论(2) 推荐(7) 编辑
摘要: 原文链接:http://xiaomage.blog.51cto.com/293990/72755linux下用g++编译代码,在连接一个c的静态库的时候,总是提示:undefined reference to`错误,找不到库函数。main.c:(.text+0x15): undefined reference to `MemoryContextInit()'main.c:(.text+0x26): undefined reference to `MemoryContextDestory()'用gcc编译就可以通过。其实,代码不是面向对象的c++语言,开始没有想到是c++调用c函 阅读全文
posted @ 2011-05-30 08:49 Richard Zhong 阅读(1659) 评论(0) 推荐(0) 编辑
摘要: #include <stdio.h>#include <stdlib.h>#include <string.h>template <class T>voidmerge(T* array, int left, int mid, int right, T* temp){ int i =left; int j =mid+1; int p=0; while(i<=mid && j <=right){ if(array[i]>array[j]){ temp[p++]=array[j++]; }else{ temp[p++] 阅读全文
posted @ 2011-04-30 16:25 Richard Zhong 阅读(135) 评论(0) 推荐(1) 编辑
摘要: #include <stdio.h>#include <stdlib.h>template <class T>voidswap(T& a, T& b){ T temp; temp=a; a=b; b=temp;}template <class T>voidpartion(T* array, int left, int right){ if(left >= right ) return; int low=left; int hight=right-1; while(low<=hight){ while(array[low 阅读全文
posted @ 2011-04-30 12:55 Richard Zhong 阅读(130) 评论(0) 推荐(1) 编辑