![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
Mr. HLW
这个作者很懒,什么都没留下…
展开
-
KMP算法
#include using namespace std; typedef struct str { char ch[20]; int length; }Str; void getNext(Str sub, int next[]) { next[0] = -1; for (int i = 1; i < sub.length; i++) { //例:ABABABB 假设比较最后一个B原创 2016-07-24 18:48:52 · 373 阅读 · 0 评论 -
银行家算法
#include using namespace std; #define n 5 #define m 3 int Allocation[n][m]; //已分配的资源 int Max[n][m];//最大需求 int Need[n][m];//需求 MAX - Allocation = Need int A = 10, B = 5, C = 7; //初始可用资源 void原创 2016-08-08 19:14:38 · 752 阅读 · 0 评论 -
Kruskal最小生成树算法
#include using namespace std; int arcNum = 9;// 边数为9 int ptNum = 6; struct edge { int start; int end; int weight; }a[9] = { {1,2,34},{1,3,46},{1,6,19}, {2,5,12},{4,5,38},{4,6,25},{3,4,17},{3,6,25},原创 2016-07-22 09:16:39 · 371 阅读 · 0 评论 -
哈希表之除留余数法+线性探测法,链地址法,公共溢出区法
线性探测法 #include using namespace std; #define HASHSIZE 10 #define NULLKEY -32768 typedef struct hash { int *element; }HashTable; void Init(HashTable *p) { p->element = (int*)malloc(sizeof(int)*HASHSI原创 2016-08-01 16:09:59 · 6827 阅读 · 1 评论 -
弗洛伊德最短路径算法
#include using namespace std; #define MAX 1000 typedef struct graph { int e; int n; int arcs[10][10]; }Graph; Graph gra; //O(n^3) void Init() { for (int i = 0; i < 10; i++) for (int j = 0; j < 1原创 2016-07-31 17:57:33 · 516 阅读 · 0 评论 -
邻接表与邻接矩阵的深度优先算法和广度优先算法
邻接矩阵 邻接表的深度优先与广度优先算法原创 2016-07-29 20:35:17 · 1877 阅读 · 0 评论 -
静态链表
# include # include #include using namespace std; # define MAXSIZE 50 //静态链表 typedef struct { int pos; // 代表在数组中的位置 char data; //代表存放的值 int nextPos; //代表它下一个节点在数组中的位置 }NODE; //示例输入: 0 a 2 1 f 7原创 2016-07-30 17:56:48 · 363 阅读 · 0 评论 -
线索二叉树
#include using namespace std; #define MAL (NODE*)malloc(sizeof(NODE)) //线索二叉树 //如果ltag=0则指向左孩子,如果ltag=1,则表示lchild为线索,指向直接前驱。 //如果rtag=0则指向右孩子,如果rtag=1,则表示rchild为线索,指向直接后继。 typedef struct node { char原创 2016-07-30 17:54:53 · 266 阅读 · 0 评论 -
BST二叉查找树
#include using namespace std; typedef struct node { int data; struct node* lchild; struct node* rchild; }NODE; //注:平均深度 O(log N) void Insert(NODE *&p, int x) { if (p == NULL) { p = (NODE*)mallo原创 2016-07-30 17:53:29 · 263 阅读 · 0 评论 -
堆排序
#include using namespace std; void Adjust(int a[],int k, int n) { int i; int temp = a[k]; //待判断的节点 for(i=2*k;i<=n;i*=2) //i*2 下一次循环时就会指向当前的左孩子节点 { if (i < n && a[i] < a[i + 1]) //如果右孩子较大则让i指向右孩子原创 2016-07-30 17:51:03 · 221 阅读 · 0 评论 -
基数排序
#include #include using namespace std; /* 三趟排序的变化 930 63 83 184 505 278 8 109 589 269 505 8 109 930 63 269 278 83 184 589 8 63 83 109 184 269 278 505 589 930 */ //时间复杂度 O(d(n+r_d)) d为关键字的位数 int a原创 2016-07-30 17:50:23 · 369 阅读 · 0 评论 -
dijkstra单源最短路径
执行过程 步骤 S集合中 U集合中 1 选入A,此时S ={A} 此时最短路径A->A = 0 以A为中间点,从A开始找 U = {B, C, D, E, F} A->B = 6 A->C = 3 A->U中其他顶点 = ∞ 其中A->C原创 2016-07-15 08:38:10 · 439 阅读 · 0 评论 -
哈夫曼树与哈夫曼编码
#include #include typedef struct { int weight; int lchild, rchild, parent; }HFTNode; typedef HFTNode HFMT[100]; //HFMT类型为有100个HFNode int n; void initHFMT(HFMT T)//初始化 { int i; printf("输入权值个数:\n");原创 2016-07-08 11:16:24 · 457 阅读 · 0 评论 -
二叉树的基本操作
#include #include #include #define MAL (NODE*)malloc(sizeof(NODE)) typedef struct node { char data; struct node*lchild; struct node *rchild; }NODE; NODE *Create()//创建一个二叉树 { NODE *p; char ch; ch原创 2016-07-08 11:06:11 · 246 阅读 · 0 评论 -
二叉树非递归求深度和节点个数
int num = 1; void levelPrint(NODE *t) { int size=1; int deep = 0; NODE * queue[20]; int front = -1,rear=0; queue[0] = t; NODE *p = t; while (front != rear) { while (size > 0) { front++;原创 2016-07-17 16:10:42 · 1266 阅读 · 0 评论 -
排序算法
#include using namespace std; int a[10] = {6,2,4,8,1,5,3,0,7,9}; void quick_sort(int left, int right); void Merge(int* list1,int list_size,int* list2,int list2_size); void MergeSort(int arry[10], int原创 2016-07-17 07:55:46 · 283 阅读 · 0 评论 -
数据结构-堆
在看libevent时看到它用小根堆来管理时间,忽然猛地发现堆的概念有点忘了(上一次看数据结构是两年半之前的一个暑假),所以此处复习一下。 堆是利用完全二叉树来维护的一种数据结构,存取操作时间复杂度在O(1)-O(log n)之间,完全二叉树就是除了最后一层外,其他所有层都是满节点,且最后一层如果缺少节点,缺的部分应该在最右边。 堆分为两种类型,大根堆与小根堆,以大根堆为例,每个节点都小于它的父节...原创 2018-12-06 20:44:51 · 291 阅读 · 0 评论