
数据结构
冷眼观world
社畜
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
树
这里采用将数据先全部存储数组vec中,再构造树#include <iostream>#include <cstdlib>#include <vector>#include <queue>#include <algorithm>using namespace std;struct node{ int val; node* left; node* right; node(int v) : val(v), left(NULL),原创 2020-07-04 21:47:41 · 257 阅读 · 0 评论 -
并查集
定义利用一个数组实现并查集int father[N];其中father[i]表示元素i的父亲结点,比如father[1] = 2说明1的父亲结点是元素2;而如果father[i] == i则说明i是该集合的根节点。father[1] = 1;father[2] = 1;father[3] = 2;father[4] = 2;父亲关系图: 1 | 2 / \ 3 4基本操作初始化刚开始每个元素都是独立的集原创 2020-07-05 15:44:42 · 170 阅读 · 0 评论 -
图的存储
邻接矩阵法#include <iostream>#include <cstdlib>#include <climits>#include <map>#define Max 100#define INFINIT INT_MAXusing namespace std;struct MGraph{ int edge[Max][Max];...原创 2020-04-30 22:31:41 · 134 阅读 · 0 评论 -
最小生成树
快速导航Prim算法邻接矩阵版邻接表版Kruskal算法Prim算法基本思想是对图G[V, E]设置集合S来存放已被访问的顶点,然后执行n次以下两个步骤每次从集合V-S(即未访问的点)中选择和集合S最近的一个顶点u,访问u并将其加入集合S,同时把这条离集合S最近的边加入最小生成树中令顶点u作为集合S和集合V-S连接的接口,优化从u能到达的未访问顶点v与集合S的最短距离实现该算法需要两个概念:集合S的实现实现方法和Dijkstra中相同,用一个bool型数组(或map)visit[]来表原创 2020-10-21 13:36:10 · 285 阅读 · 0 评论