邻接矩阵实现图的构造 (包含有向图和无向图) 实现 插入或者删除 顶点、边

代码与相关注释如下:

#include<iostream>
#include<cstring>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
const int maxWeight = RAND_MAX; //无穷大的值
const int DefaultVertices = 10;	//默认的顶点数,不妨设为10 
template <class T, class E>
class Graph {
   
protected:
    int maxVertices=30;//图中最大顶点数
    int numVertices=0;//图中当前顶点数
    int numEdges=0;//图中当前边数
    bool direction=false;//图中边的是否有方向
    bool withCost=false;//图中的边是否带权
    //返回顶点名vertex的序号(从0开始)
	int getVertexPos (T vertex);	
public:                                        
    Graph (int sz , bool direct, bool cost); 
  	~Graph();//析构函数
    bool GraphEmpty () const//判图是否为空,因为只是判断,不修改,所以可以定义为常成员函数 
    {
    
	 return numEdges == 0; 
	}
    bool GraphFull() const;         //判图满
    //返回图中当前顶点数
   	int NumberOfVertices ()
	{
    
	return numVertices;
	}
    //返回图中当前边数
	int NumberOfEdges ()
	{
    
	return numEdges;
	}
	//取回序号为 i 的顶点值(顶点名)
	virtual T getValue (int i) 
	{
   
	}
    //取顶点序号为v1,v2的边上权值
    virtual E getWeight (int v1, int v2)
	{
   
	}   
//取顶点 v 的第一个邻接顶点序号
    virtual int getFirstNeighbor (int v)
	{
   
	}
   //返回顶点 v 和邻接顶点 w 的下一个邻接顶点序号
	virtual int getNextNeighbor (int v, int w)
	{
   
	}
    //插入新顶点,顶点名为vertex
	virtual bool insertVertex (const T vertex)
	{
   
	}
    //插入新边(v1,v2), 权值cost
	virtual bool insertEdge (T  v1, T  v2, E cost)
	{
   
	}
    //删除名为 v 的顶点和所有与它相关联的边
	virtual bool removeVertex (T v)
	{
   
	}
    //在图中删除边(v1,v2)
	virtual bool removeEdge (T v1, T v2)
	{
   
	}	
};
template<class T , class E>
Graph<T,E>::Graph (int sz , bool direct, bool cost)
{
   
	 sz = DefaultVertices,  direct=false,  cost=false;
}
template<class T , class E>
Graph<T,E>::~Graph()
{
   
}
//图类的实现 

template <class T, class E> //邻接矩阵图类继承图类
class Graphmtx : public Graph<T,E> {
   
   public :
   	void Enter (void); //输入图中所有顶点和边的信息
	void Print (void); //输出图中所有顶点和边的信息
protected:
    T* VerticesList; //顶点名表数组 
   	E** Edge;	//边邻接矩
  • 6
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

是牛大春呀

老板糊涂啊

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值