【图】邻接矩阵及最小生成树(C++)

#include<iostream>
#include<queue>
#include<string>
#include<fstream>
#include<iomanip>
using namespace std;

const int MaxSize=10;

//辅助prim 
struct shortEdge{
	int edgeIndex;  //边的编号 
	int lowcost;    //最小权值 
};

template<class DataType>//由于顶点数据的类型不确定 
class Graph
{
private:
	int GType;//图的类型0:无向图  1:有向图
	DataType vertex[MaxSize];//定义数组,保存顶点数据
	int edge[MaxSize][MaxSize];//边
	int vertexNum, edgeNum;
	int isTrav[MaxSize];
	int visited[MaxSize];

public:	
	Graph(DataType a[], int n, int e);//构造函数,简历具有n个顶点,e条边的图
	~Graph(){ } //析构函数为空
	void resetVisted();
	void DFSTraverse(int v);//Depth—first traverse深度优先遍历
	void BFSTraverse(int v);//Breadth—first traverse广度优先遍历
	
	template<class T>
	friend void prim(Graph<T> G);//友元函数,用于访问类中的私有成员。最小生成树的prim算法 
};

//构造函数 
//邻接矩阵初始化为-1,表示没有路径
template<class DataType>
Graph<DataType>::Graph(DataType a[], int n, 
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值