自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(1)
  • 资源 (11)
  • 收藏
  • 关注

原创 B树的C++实现

最近写一个程序需要用到 B 树,翻书看了下,参照网上的代码写了一个。对于 B 树的定义和生成有不少的文章讲过,我就不多废话,直接贴代码。  这里面主要包含两个类,CBTree 和 CDataTypeForBtree,其余几个是测试用的。B 树的实现类 CBTree 里面,关键字实际保存的是地址,虽然也可以保存无符号整数,但显然这不是我的初衷,我想让这一个 B 树类能够处理不同类型的数据

2013-10-30 19:18:24 989 6

B树的C++源代码及测试代码

使用方法: #include <string h> #include <stdio h> #include "DataTypeForBtree h" #include "BTree h" struct tree data { char tid[37]; char tname[63]; unsigned int aid; unsigned int id; }; class CMyDataTypeForBtree : public CDataTypeForBtree { public: virtual void Print void key FILE fp { if NULL key || NULL fp return; struct tree data tr struct tree data key; fprintf fp "%u %u %s %s n" tr >id tr >aid tr >tid tr >tname ; } virtual int Compare void p1 void p2 { if NULL p1 || NULL p2 return int unsigned int 0 >> 1 ; 返回一个大点的数表示失败 struct tree data tr1 tr2; tr1 struct tree data p1; tr2 struct tree data p2; if tr2 >aid tr1 >aid { return tr1 >aid tr2 >aid; } if " 0" tr1 >tid[0] && " 0" tr2 >tid[0] { return strcmp tr1 >tname tr2 >tname ; } return strcmp tr1 >tid tr2 >tid ; } CMyDataTypeForBtree { } virtual CMyDataTypeForBtree { } }; int main int argc char argv[] { CMyDataTypeForBtree dt new CMyDataTypeForBtree; CBTree tree dt 5 ; struct tree data tr[101] {{"asd" "4Hero" 1 1} {"abc" "Underworld" 1 0} {"bac" "Samantha" 1 2} {"cass" "Gelka" 1 3} {"mark" "Clark"

2013-11-05

B树的C++实现

用 C++ 实现的一个 B 树类,有注释,但不知道我写得能不能看明白。使用时先要从类 CDataTypeForBtree 派生一个类出来,在派生类中实现数据比较函数 Compare,数据输出函数 Print。然后在堆上创建一个数据类对象,把地址作为构造函数的参数创建树对象,下面给出一个使用示例。 #include <string.h> #include <stdio.h> #include "DataTypeForBtree.h" #include "BTree.h" struct tree_data { char tid[37]; char tname[63]; unsigned int aid; unsigned int id; }; class CMyDataTypeForBtree : public CDataTypeForBtree { public: virtual void Print(void *key, FILE* fp) { if(NULL == key || NULL == fp) return; struct tree_data* tr = (struct tree_data*)key; fprintf(fp, "%u %u %s %s\n", tr->id, tr->aid, tr->tid, tr->tname); } virtual int Compare(void *p1, void *p2) { if(NULL == p1 || NULL == p2) return (int)(((unsigned int)(~0)) >> 1); //返回一个大点的数表示失败 struct tree_data *tr1, *tr2; tr1 = (struct tree_data*)p1; tr2 = (struct tree_data*)p2; if(tr2->aid != tr1->aid) { return tr1->aid - tr2->aid; } if('\0' == tr1->tid[0] && '\0' == tr2->tid[0]) { return strcmp(tr1->tname, tr2->tname); } return strcmp(tr1->tid, tr2->tid); } CMyDataTypeForBtree() { } virtual ~CMyDataTypeForBtree() { } }; int main(int argc, char* argv[]) { CMyDataTypeForBtree *dt = new CMyDataTypeForBtree; CBTree tree(dt, 5); struct tree_data tr[101] = {{"asd", "4Hero", 1, 1}, {"abc", "Underworld", 1, 0}, {"bac", "Samantha", 1, 2}, {"cass", "Gelka", 1, 3}, {"mark", "Clark", 1, 4}, {"gone", "Woolfy", 1, 5}, {"word", "Production", 1, 6}, {"paper", "Jimpster", 1, 7}, {"Richie", "Hawtin", 1, 8}, {"John", "Matthias", 1, 9}, {"Lou", "Donaldson", 1, 10}, {"Lady", "Alma", 1, 11}, {"Mass", "Slick", 1, 12}, {"Clyde", "Alexander", 1, 13}, //……省略若干,省略部分在下载包里面有 {"", "I'M Not Sayin' Get 'Er Done, But Don'T Just Stand There", 11, 101},}; for(int i = 0; i < 101; i++) { tree.Insert((void*)(tr + i)); } tree.DelKey((void*)(tr + 5)); tree.Traverse(NULL, NULL); tree.DelKey((void*)(tr + 13)); tree.Traverse(NULL, NULL); //输出到标准输出,可以重定向到文件 return 0; }

2013-10-30

算法导论第二版-part3

算法导论第二版,(美)科曼(Cormen.T.H.)等著,潘金贵等译。不是那种只有半页的。这是29章以后的部分,三部分均免费下载。

2013-07-04

算法导论第二版-part2

算法导论第二版,(美)科曼(Cormen.T.H.)等著,潘金贵等译。不是那种只有半页的。这是前17-28章,三部分均免费下载。

2013-07-04

算法导论第二版-part1

算法导论第二版,(美)科曼(Cormen.T.H.)等著,潘金贵等译。不是那种只有半页的。这是前16章,三部分均免费下载。

2013-07-04

libsvm-3.17

支持向量机源码,可在 www.csie.ntu.edu.tw/~cjlin/libsvm/ 下载到最新版本,该版本是 2013年4月更新的,3.17 版。压缩包里面有源代码和文档。以下摘自前述网站: Introduction LIBSVM is an integrated software for support vector classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and distribution estimation (one-class SVM). It supports multi-class classification. Since version 2.8, it implements an SMO-type algorithm proposed in this paper: R.-E. Fan, P.-H. Chen, and C.-J. Lin. Working set selection using second order information for training SVM. Journal of Machine Learning Research 6, 1889-1918, 2005. You can also find a pseudo code there. (how to cite LIBSVM) Our goal is to help users from other fields to easily use SVM as a tool. LIBSVM provides a simple interface where users can easily link it with their own programs. Main features of LIBSVM include Different SVM formulations Efficient multi-class classification Cross validation for model selection Probability estimates Various kernels (including precomputed kernel matrix) Weighted SVM for unbalanced data Both C++ and Java sources GUI demonstrating SVM classification and regression Python, R, MATLAB, Perl, Ruby, Weka, Common LISP, CLISP, Haskell, OCaml, LabVIEW, and PHP interfaces. C# .NET code and CUDA extension is available. It's also included in some data mining environments: RapidMiner, PCP, and LIONsolver. Automatic model selection which can generate contour of cross valiation accuracy.

2013-06-25

集体智慧编程随书代码

集体智慧编程随书代码 ├─chapter2 │ deliciousrec.py │ pydelicious.py │ recommendations.py │ ├─chapter3 │ blogdata.txt │ clusters.py │ downloadzebodata.py │ feedlist.txt │ generatefeedvector.py │ Thumbs.db │ zebo.txt │ ├─chapter4 │ nn.py │ searchengine.py │ ├─chapter5 │ dorm.py │ kayak.py │ optimization.py │ schedule.txt │ socialnetwork.py │ ├─chapter6 │ docclass.py │ feedfilter.py │ python_search.xml │ test.db │ test1.db │ ├─chapter7 │ addresslist.txt │ hotornot.py │ Thumbs.db │ treepredict.py │ zillow.py │ ├─chapter8 │ ebaypredict.py │ numpredict.py │ optimization.py │ ├─chapter9 | advancedclassify.py | agesonly.csv | facebook.py | matchmaker.csv | svm.py | svm.pyc | svmc.pyd | ├─chapter10 │ articles.txt │ clusters.py │ docclass.py │ features.txt │ newsfeatures.py │ nnmf.py │ stockfeatures.txt │ stockvolume.py │ Thumbs.db │ └─chapter11 gp.py gp.pyc

2013-06-18

pysqlite-2.6.3.win32-py2.7

pysqlite-2.6.3.win32-py2.7

2013-04-27

BoUml-6.4.4

开源UML工具,可以生成包括 C++/Java/Idl/PHP/Python 等代码,支持操作系统包括: Unix/Linux/Solaris, MacOS X 和 Windows。

2013-03-21

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除