数据结构C++实现
文章平均质量分 71
hit_fantasy
圣马家沟铁路男子职业技工学校大三信息安全专业学生
展开
-
线索二叉树三种遍历算法(前序中序后序)
前序和中序线索二叉树的实现: #include using namespace std; struct node { int data;//数据域 node*left;//左子树 node*right;//右指针 bool ltag;//左标志 1: youxiansuo 0:muyou bool rtag;//右标志 }; class binary原创 2013-03-25 23:27:28 · 2016 阅读 · 1 评论 -
有向图邻接矩阵实现
DFS写了递归和非递归方法: #ifndef GRAPH_H_ #define GRAPH_H_ #define MAXSIZE 100 #include #include #include using namespace std; template class Graph { public: Graph(T a[],int n,int e);//构造函数 void DF原创 2013-03-27 21:35:48 · 999 阅读 · 0 评论 -
并查集的表示与等价分类
最简单的实现,为了凑软件设计作业。。。没有做优化。 #include #include using namespace std; //equivalence means deng jia lei class equivalence { protected: int *parent; int size; int find(int cur)const; public:原创 2013-03-26 23:47:15 · 940 阅读 · 0 评论 -
有向加权图的邻接表实现
稀疏图这样做可以省空间,不过邻接表写算法蛋疼了很多,我还是喜欢用矩阵的。。。 // cunzai direction and value de listGraph #ifndef listGRAPH_H_ #define listGRAPH_H_ #define MAXSIZE 100 #include #include #include #include using namespace原创 2013-03-27 21:41:40 · 2526 阅读 · 0 评论 -
二叉树数组存储结构实现
不是满二叉树的话非常浪费空间,一般就在堆排序中用了,写这个一般操作纯粹是因为坑爹的软设作业= = #ifndef arrayBinaryTree_H_ #define arrayBinaryTree_H_ #define maxsize 1000 #include #include #include #include using namespace std; class arrayB原创 2013-03-26 22:12:27 · 770 阅读 · 0 评论 -
树的邻接表表示法
实现了书上这样的存储方式: #ifndef listTree_H_ #define listTree_H_ #include #include #include #include #include using namespace std; struct childNode { int child; childNode *next; }; struct he原创 2013-03-26 16:02:24 · 2493 阅读 · 0 评论 -
堆排序的实现
先从最后一个非终端节点开始调整,接着调整前一个节点,一直到顶,初始构建堆。 然后输出堆顶,用最后一个节点代替堆顶,然后从上往下撸一遍,循环输出堆顶即可。 //heap sort #include using namespace std; template void exchange(elemType &a,elemType &b) { elemType temp=a; a原创 2013-03-26 15:47:56 · 563 阅读 · 0 评论 -
关键路径求解算法
关键路径求解要用到拓扑排序,先从头往后拓扑,在ve[i]中记录每个事件的最早发生时间。 然后把ve[]的值赋给vl[],从后边向前求每个事件的最迟发生时间,记录在vl[]中。 如果ve[]中的值和vl[]中的值对应相等,则这个事件在关键路径上。 假设初始AOE网是这样的: 关键路径: 代码: #include #include #include #includ原创 2013-04-09 17:09:33 · 1374 阅读 · 0 评论 -
AVL树的实现
升级版的二叉搜索树,插入和删除时要注意调整平衡。 #ifndef avlTree_H_ #define avlTree_H_ #include using namespace std; class treeNode { public: treeNode():lchild(NULL),rchild(NULL),height(1),freq(1){} int data;原创 2013-03-26 15:52:03 · 804 阅读 · 0 评论 -
Huffman树实现与应用(编码解码压缩解压缩)
在目录中放一个"in.txt"文件,里边放一篇英语文章,用来统计各个字符出现的频率,从而建树。 哈夫曼树头文件: #ifndef HUFFMAN_H_ #define HUFFMAN_H_ #include #include #include using namespace std; void SelectMin(int weight[],int &amount,int &x,int原创 2013-03-26 16:21:51 · 1156 阅读 · 0 评论 -
树的孩子兄弟表示法
#ifndef childSiblingTree_H_ #define childSiblingTree_H_ #include #include #include #include using namespace std; typedef struct csnode { char data; csnode *firstChild,*nextSibling; }*cstr原创 2013-03-26 16:07:17 · 935 阅读 · 0 评论 -
拓扑排序算法
用indegree来记录每个点的入度,每次输出入度为0的点,然后继续往后找。 #include #include #include #include using namespace std; int map[101][101]; int indegree[101]; int n,m; bool topoSort() { queue Q; int nodeCount=0原创 2013-04-08 16:02:37 · 807 阅读 · 0 评论 -
闭散列表及其查找算法的实现
在一个数组中模size进行散列,用count来判满,也叫开放地址法。 #ifndef openAddress_H_ #define openAddress_H_ #include using namespace std; struct openAddressNode { int data; bool used; }; class hashTable { private:原创 2013-04-01 21:07:36 · 1733 阅读 · 0 评论 -
开散列表及其查找算法的实现
一个头结点数组,散列后的元素插入数组元素后的链表中。 #ifndef listAddress_H_ #define listAddress_H_ #include using namespace std; struct node { int data; node* next; }; class hashTable { private: int size; n原创 2013-04-01 21:03:58 · 1090 阅读 · 0 评论 -
排序性能测试比较
用了头文件“sort.h” 附链接: http://blog.csdn.net/hit_fantasy/article/details/8739985 用rand()生成随机数组,然后用start=clock(); XXXXSort(a,len); finish=clock();来计时。 基数排序没有做,不知道怎么确定基数。 #include #include #include原创 2013-03-30 14:22:27 · 667 阅读 · 0 评论 -
各种排序实现
冒泡排序、选择排序、插入排序、希尔排序、归并排序、快速排序、基数排序、堆排序的实现: #ifndef Sort_H_ #define Sort_H_ #include #include #include #include #include using namespace std; inline void exchange(int &a,int &b) { int temp=a原创 2013-03-30 14:17:47 · 884 阅读 · 0 评论 -
双数组AC自动机(doubleArrayTrie)的实现
按照PPT上的描述写了个最简单的版本,没敢测大数据。 主要是几个表的构建: 首先构建next,base,check表。 根据失效函数的定义:父状态的失效函数输入当前字符,可得出每个状态的失效函数(要转移到的状态) 可以发现每个状态要转移到的状态是一定的,如下图: 所以可以构造一个fail表,由上述三个表来构建。 为了输出方便,又构造了一个output表。 代码如下: #incl原创 2013-12-13 23:29:34 · 4835 阅读 · 0 评论