数据结构
2014乘风破浪2014
技术,没有止境
展开
-
哈夫曼编码实现
#include #include #include #include #include #define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define OVERFLOW -2using namespace std;typedef struct Node{ char data; int num原创 2016-05-15 11:38:13 · 1007 阅读 · 0 评论 -
SPFA算法
算法介绍:求单源最短路在Bellman-Ford算法基础上加队列优化,减少了冗余的松弛操作松弛操作必定只会发生在最短路径前导节点上,用一个队列记录松弛过的节点,可以避免了冗余计算,将复杂度降低到0(kE)(注:一般k<=2,也可能很大)算法过程:建立一个队列,初始时队列里只有起始点;建立存储最短距离的数组,初始化为无穷大用队列里的点松弛起始点到所有点的最短路,如果刷新成功且被刷新点不在队原创 2017-03-30 15:42:02 · 707 阅读 · 0 评论 -
next_permutation函数
博客来自:http://blog.sina.com.cn/s/blog_9f7ea4390101101u.html这是一个求一个排序的下一个排列的函数,可以遍历全排列,要包含头文件 下面是以前的笔记 与之完全相反的函数还有prev_permutation(1) int 类型的next_permutationint main() { int a[3]; a[0]=1;a[1]=2;a[原创 2016-03-05 15:59:00 · 839 阅读 · 0 评论 -
Bellman-ford 算法
若图中出现负权的边,dijstra就会失效,此时可以使用该算法(优化的该算法在后面讲到)算法过程:数组Dis[i]记录源点到i的最短距离,s为源点,初始化Dis[i]=无穷大,Dis[s]=0设n为顶点数,循环n-1次,对于每一条边e(u,v),如果Dis[u]+e(u,v) < Dis[v],则Dis[v]=Dis[u]+e(u,v)。为检测图中是否有负环:对于每一条边e(u,v),如果存在原创 2017-03-29 13:52:47 · 381 阅读 · 0 评论 -
树高和树深
一直有点迷茫这两个概念,后来查了资料,发现正确的解答应该是这样:树高:从最下面的叶子结点开始数,数到当前结点,就是树的高度,类似于楼高,我们一般从楼的最下面开始往上数。 树深:从根节点往下数,数到当前结点。原创 2016-11-11 17:07:21 · 1043 阅读 · 0 评论 -
图的深度和广度遍历(邻接矩阵)
这里我采用邻接矩阵的存储方式对图进行遍历#include #include #define INFINITY 100#define MAXNODE 100#define OK 1using namespace std;typedef char VertexType;int vis[MAXNODE];typedef struct{ int adj;} ArcType;t原创 2016-05-10 23:32:01 · 2276 阅读 · 0 评论 -
顺序表的操作
编程实现顺序表的以下基本操作:建立顺序表,修改顺序表,插入顺序表,删除顺序表。#include #include #include #define LIST_INIT_SIZE 100#define LISTINCREMENT 10#define OK 1#define OVERFLOW -2#define ERROR 0using namespace std;typed原创 2016-05-15 11:23:47 · 1104 阅读 · 0 评论 -
顺序栈的操作
#include <iostream>#include <stdlib.h>#define STACK_INIT_SIZE 100#define STACKINCREMENT 10#define ERROR -1#define OK 1#define OVERFLOW -1using namespace std;typedef struct{ int *base;原创 2016-05-15 11:34:53 · 823 阅读 · 0 评论 -
顺序栈实现括号匹配
//采用顺序栈编程实现:表达式的括号是否匹配问题。//要求:输入带括号的表达式,判断其中括号是否配对。//扩展功能:给出配对括号的位序和不配对括号的位序。#include <iostream>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <algorithm>#define OVERFLOW -2原创 2016-05-15 11:33:58 · 2624 阅读 · 0 评论 -
顺序表实现集合运算
采用顺序表结构编程实现:两个集合的运算:交集 并集 差集#include #include #include #define LIST_INIT_SIZE 100#define LISTINCREMENT 10#define OK 1#define OVERFLOW -2#define ERROR 0using namespace std;typedef struct{原创 2016-05-15 11:25:46 · 6264 阅读 · 0 评论 -
二叉树(遍历 树高 叶子节点个数)
#include #include #include #include #include #define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1#define OVERFLOW -2using namespace std;typedef char原创 2016-04-21 17:22:28 · 1082 阅读 · 0 评论 -
最小生成树Prim算法(邻接矩阵)
#include #include #include #define INFINITY INT_MAX#define OK 1#define MAXNODE 100using namespace std;typedef char VertexType;typedef struct{ int adj;}ArcType;typedef struct{ ArcTy原创 2016-05-15 11:20:02 · 4558 阅读 · 0 评论 -
有序单链表的归并运算。
采用单链表结构编程实现:两个有序单链表的归并运算。#include #define ERROR 0#define OK 1#include using namespace std;typedef int ElemType;typedef int Status;typedef struct LNode{ ElemType data; struct LN原创 2016-05-15 11:31:50 · 2169 阅读 · 3 评论 -
树的遍历
#include <iostream>#include <stdio.h>#include <stdlib.h>#include <queue>#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1#define OVERFLOW -2using namespace std;type原创 2016-05-15 11:36:20 · 889 阅读 · 0 评论 -
链表操作
编程实现单链表的以下基本操作:建立单链表,查找单链表,插入单链表,删除单链表。原创 2016-05-15 11:27:18 · 2137 阅读 · 2 评论