开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 127

berky/数据结构(C++模板实现)

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (3)
master
Prometheus
dev
master
分支 (3)
master
Prometheus
dev
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (3)
master
Prometheus
dev
data-structures-cpp
/
Graph
/
src
/
graph_algorithm.h
data-structures-cpp
/
Graph
/
src
/
graph_algorithm.h
graph_algorithm.h 6.50 KB
一键复制 编辑 原始数据 按行查看 历史
Y_Dash 提交于 2023年07月03日 18:41 +08:00 . 增加部分readme代码指向
/*!
* @file graph_algorithm.h
* @author CyberDash计算机考研, cyberdash@163.com(抖音id:cyberdash_yuan)
* @brief 图算法h文件
* @version 0.2.1
* @date 2021年02月04日
*/
#ifndef CYBER_DASH_GRAPH_ALGORITHM_H
#define CYBER_DASH_GRAPH_ALGORITHM_H
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include "graph.h"
using namespace std;
/*!
* @brief **最小生成树模板类**
* @tparam TVertex 结点类型模板参数
* @tparam TWeight 边权值类型模板参数
*/
template<typename TVertex, typename TWeight>
class MinimumSpanTree {
public:
/*!
* @brief **构造函数(边数上限)**
* @param max_size 边数上限
* @note
* 构造函数
* -------
* -------
*
* -------
* mst_edges_分配内存\n
* **if** 内存分配失败 :\n
* &emsp; 抛出bad_alloc()\n
*
*
* -------
*/
explicit MinimumSpanTree(int max_size): max_size_(max_size), size_(0) {
this->mst_edges_ = new Edge<TVertex, TWeight>[max_size]; // mst_edges_分配内存
if (!this->mst_edges_) { // if 内存分配失败
throw bad_alloc(); // 抛出bad_alloc()
}
}
/*!
* @brief **插入边**
* @param edge 边
* @return 当前最小生成树边的数量
* @note
* 插入边
* -----
* -----
*
* -----
* + **1 合法性判断**\n
* **if** 当前边数量 >= 最大边数量 :\n
* &emsp; 返回-1\n
* + **2 执行插入**\n
* &emsp; 插入到最后一项\n
* &emsp; size_加1\n
*
*
* -----
*/
int Insert(Edge<TVertex, TWeight>& edge) {
// ---------- 1 合法性判断 ----------
if (size_ >= max_size_) { // if 当前边数量 >= 最大边数量 :
return -1; // 返回-1
}
// ---------- 2 执行插入 ----------
mst_edges_[size_] = edge; // 插入到最后一项
size_++; // size_加1
return size_ - 1;
}
/*!@brief 显示最小生成树
* @note
* 显示最小生成树
* -------------
* -------------
*
* -------------
* 初始化total_weight(总权值)
* **for loop** 遍历最小生成树 :\n
* &emsp; 获取当前边权值\n
* &emsp; 打印当前边信息\n
* 打一段文本\n
*
*
* -------------
* */
void Print() {
TWeight total_weight = 0; // 初始化total_weight(总权值)
for (int i = 0; i < this->size_; i++) { // for loop 遍历最小生成树
total_weight += this->mst_edges_[i].weight;
cout << "starting_vertex: " << this->mst_edges_[i].starting_vertex // 获取当前边权值\n
<< ", ending_vertex: " << mst_edges_[i].ending_vertex // 打印当前边信息\n
<< ", weight: " << mst_edges_[i].weight << endl;
}
cout << "最小生成树边, 总权值: " << total_weight << endl; // 打一段文本\n
}
protected:
Edge<TVertex, TWeight>* mst_edges_; //!< **最小生成树边数组**
int max_size_; //!< **边数上限**
int size_; //!< **当前边数量**
};
// 深度优先遍历
template<typename TVertex, typename TWeight>
void Dfs(const Graph<TVertex, TWeight>& graph, const TVertex& vertex);
// 深度优先遍历(递归)
template<typename TVertex, typename TWeight>
void DfsOnVertexRecursive(const Graph<TVertex, TWeight>& graph, const TVertex& vertex, set<TVertex>& visited_vertex_set);
// 图广度优先遍历
template<typename TVertex, typename TWeight>
void Bfs(const Graph<TVertex, TWeight>& graph, const TVertex& vertex);
// 拓扑排序
template<typename TVertex, typename TWeight>
bool TopologicalSort(const Graph<TVertex, TWeight>& graph,
const TVertex& starting_vertex,
vector<TVertex>& topology_sorted_list);
// 求图的连通分量
template<typename TVertex, typename TWeight>
int Components(const Graph<TVertex, TWeight>& graph);
// 最小生成树Prim
template<typename TVertex, typename TWeight>
bool Prim(const Graph<TVertex, TWeight>& graph, MinimumSpanTree<TVertex, TWeight>& min_span_tree);
// 最小生成树Kruskal
template<typename TVertex, typename TWeight>
void Kruskal(const Graph<TVertex, TWeight>& graph, MinimumSpanTree<TVertex, TWeight>& min_span_tree);
// 迪杰斯特拉(Dijkstra)最短路径(优先队列)
template<class Vertex, class Weight>
void Dijkstra(const Graph<Vertex, Weight>& graph,
const Vertex& starting_vertex,
Weight distance[],
int predecessor[]);
// 贝尔曼福特(Bellman-Ford)最短路径
template<typename Vertex, typename Weight>
bool BellmanFord(const Graph<Vertex, Weight>& graph,
const Vertex& starting_vertex,
Weight distance[],
int predecessor[]);
// 弗洛伊德(Floyd-Warshall)最短路径
template<class Vertex, class Weight>
void Floyd(const Graph<Vertex, Weight>& graph, vector<vector<Weight> >& distance, vector<vector<int> >& predecessor);
// 打印单源最短路径(迪杰斯特拉Dijkstra, 贝尔曼福特BellmanFord等)
template<typename TVertex, typename TWeight>
void PrintSingleSourceShortestPath(const Graph<TVertex, TWeight>& graph,
const TVertex& starting_vertex,
TWeight distance[],
const int predecessor[]);
// 打印多源最短路径(弗洛伊德Floyd等)
template<typename TVertex, typename TWeight>
void PrintMultipleSourceShortestPath(const Graph<TVertex, TWeight>& graph,
const vector<vector<TWeight> >& distance,
const vector<vector<int> >& predecessor);
// 求起点到各结点的关键路径
template<typename TVertex, typename TWeight>
vector<TWeight> GetCriticalPath(const Graph<TVertex, TWeight>& graph, const TVertex& starting_vertex);
#endif // CYBER_DASH_GRAPH_ALGORITHM_H
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

通用的C++数据结构代码实现,使用模板。代码完整,注释齐全,可直接运行,可使用doxygen生成网页和PDF文档,跨Windows/Linux/Mac平台兼容
暂无标签
MulanPSL-2.0
使用 MulanPSL-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/berky/data-structures-cpp.git
git@gitee.com:berky/data-structures-cpp.git
berky
data-structures-cpp
数据结构(C++模板实现)
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /