//头文件Edge.h Graph.h
//Edge.h
//该函数的目的是记录带权有向图
#ifndef EDGE_H
#define EDGE_H
template<typename T>
class Edge{
public:
//该图主要包括(起点,终点,权重)
int start;
int end;
T weight;
Edge();
Edge(int st, int en, T wei);
bool operator<(const Edge<T>& str);
bool operator>(const Edge<T>& str);
};
template<typename T>
Edge<T>::Edge()
{
}
template<typename T>
Edge<T>::Edge(int st, int en, T wei)
{
this->start = st;
this->end = en;
this->weight = wei;
}
template<typename T>
bool Edge<T>::operator<(const Edge<T>& str)
{
return this->weight < str->weight;
}
template<typename T>
bool Edge<T>::operator>(const Edge<T>& str)
{
return this->weight>str->weight;
}
#endif // !EDGE_H
//Graph.h
#ifndef GRAPH_H
#define GRAPH_H
#include"Edge.h"
#include<iostream>
using namespace std;
template
带权有向图
最新推荐文章于 2024-07-06 03:05:45 发布
这篇博客详细介绍了如何实现带权有向图的数据结构,包括Edge类和Graph类的定义,涵盖添加边、删除边、获取权重等功能。通过示例展示了如何使用这些功能进行操作,如设置边权重、打印边信息等。
摘要由CSDN通过智能技术生成