// 图的邻接表数据结构C++描述
#include <iostream>
using namespace std;
const int MaxVexs=20;
//前向声明
template <typename ArcType, typename VexType> class Graph;
template <typename ArcType, typename VexType> class VexNode;
// 边节点类
template <typename ArcType>
class ArcNode{
template<typename Type1, typename Type2>friend class VexNode;
template<typename Type1, typename Type2>friend class Graph;
private:
int adjvex;
ArcType weight;
ArcNode *nextarc;
ArcNode():nextarc(NULL){
}
ArcNode(int v, const ArcType& w):adjvex(v),weight(w),nextarc(NULL){
}
};
//顶点节点类
template <typename ArcType, typename VexType>
class VexNode{
friend class Graph<ArcType, VexType>;
private:
VexType data;
ArcNode<ArcType> *firstarc;
VexNode():firstarc(NULL){
}
};
// 邻接表图类
template<typename ArcType, typename VexType>
class Graph{
private:
VexNode<ArcType,VexType> *VexTable;
int CurrentNumVexs;
int CurrentNumArcs;
//int GetVexPosition(const VexType& v);
public:
Graph():VexTable(NULL),CurrentNumVexs(0),CurrentNumArcs(0){
}
Graph(VexType *v, int num=MaxVexs);
~Graph();
bool empty() {
return CurrentNumVexs==0; }
int GetNumVexs() {
return CurrentNumVexs; }
带权图(网)的邻接表存储的C++实现
最新推荐文章于 2024-08-08 16:58:40 发布
本文介绍了如何使用C++编程实现带权图(网)的邻接表存储方式,详细讲解了相关数据结构的设计和操作,包括类的定义及图的遍历算法。
摘要由CSDN通过智能技术生成