Prim+邻接矩阵储存

// TEXT.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include#include#include#includeusing namespace std;struct GraphNode //图结点{ string vertexName; //顶点名称 bool visited; //访问标记
摘要由CSDN通过智能技术生成
// 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</
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值