带权有向图

这篇博客详细介绍了如何实现带权有向图的数据结构,包括Edge类和Graph类的定义,涵盖添加边、删除边、获取权重等功能。通过示例展示了如何使用这些功能进行操作,如设置边权重、打印边信息等。
摘要由CSDN通过智能技术生成
//头文件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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值