// TEXT.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<string>
#include<vector>
#include<queue>
using namespace std;
struct GraphNode //图结点
{
string vertexName; //顶点名称
bool visited; //访问标记
float weight; //顶点权值
int index; //顶点标号
friend bool operator<(GraphNode a, GraphNode b) //自定义优先级,weight小的优先
{
return a.weight > b.weight;
}
};
template <class T>
class Graph
{
public:
//********************邻接矩阵函数************************************//
Graph(int *vertexArray, T* nameOfVertex, int numberOfVertex);//构造函数,初始化具有n个顶点的图
//~Graph();
void Prim(int source);//Prim算法
void GetVexInfo();//取顶点信息
void GetArcInfo();//输出边信息
void SetArc(int VertextFrom, int vertextTo, int arcLenth);//修改边
void DeleteVex(int vertex);//删除顶点vertex
void DeleteArc(int vertextFrom, int vertextTo);//在图中删除一条边,其依附的两个顶点的 编号为 vertextFrom 和 vertextTo
void InsertVex(int position, T name);//在position位置上插入一顶点,值为name
void InsetArc(int vertextFrom, int vertextTo, int value);//在图中插入一条边,其依附的两个顶点编号为vertextFrom和vertextTo
void PrintAdiacencyMatrix();//输出邻接矩阵
private:
int vertexNum, arcNum;//图的顶点数和边数
vector<T>vertexName; //存放图中的顶点的数组
vector<vector<int>>adjacencyMatrix;//邻接矩阵
vector< GraphNode > graphNodeArray;//存放图中顶点的数组
};
template<class T>
Graph<T>::Graph(int *vertexArray, T* nameOfVertex, int</
Prim+邻接矩阵储存
最新推荐文章于 2021-11-08 18:59:32 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)