摘要: 1 //并查集类 2 #include 3 #include 4 #include 5 6 7 using namespace std; 8 class Fmsets{ 9 vector parent_;10 11 protected:12 in... 阅读全文
posted @ 2015-07-22 17:49 喜欢算法的小杰 阅读(352) 评论(0) 推荐(0) 编辑
摘要: 1.标准初始化函数 std::fill(首地址,尾地址,value) || 用于在首尾地址之间填充value值,对应matlab的ones(1:n)函数1 template 2 void fill (ForwardIterator first, ForwardIterator last, c... 阅读全文
posted @ 2015-07-22 16:23 喜欢算法的小杰 阅读(201) 评论(0) 推荐(0) 编辑
摘要: 1 //一般树的手工打造,遍历,求节点数和树高 2 #include 3 #include 4 #include //使用向量需包含该文件 5 6 using namespace std; 7 8 template 9 struct Tnode{10 11 typedef ... 阅读全文
posted @ 2015-07-22 09:49 喜欢算法的小杰 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 1 //手工构造一颗二叉树 ,并给出递归和非递归2类7种遍历方法,树高,节点数求法和逆时针90度显示二叉树 2 //注意本文中2个 typename的使用层次 3 //递归遍历容易溢栈 4 #include 5 #include 6 #include //用到队列时需要包含... 阅读全文
posted @ 2015-07-21 18:32 喜欢算法的小杰 阅读(194) 评论(0) 推荐(0) 编辑
摘要: 1 //KMP算法实现字符串匹配 2 //该算法保证字符比较次数不超过目标串字符长度的2倍 3 #include 4 #include 5 6 using namespace std; 7 8 void compute_next(int* next,char const*p,int... 阅读全文
posted @ 2015-07-20 19:07 喜欢算法的小杰 阅读(751) 评论(0) 推荐(0) 编辑