📄 adjmwgraph.h
字号:
class AdjMWGraph
{
private:
SeqList Vertices;
int Edge[MaxVertices][MaxVertices];
int numOfEdges;
public:
AdjMWGraph(const int sz = MaxVertices);
int GraphEmpty()const
{
return Vertices.ListEmpty();
}
int NumOfVertices(void)
{
return Vertices.ListSize();
}
int NumOfEdges(void)
{
return numOfEdges;
}
VerT GetValue(const int i);
int GetWeight(const int v1, const int v2);
void InsertVertex(const VerT &vertex);
void InsertEdge(const int v1, const int v2, int weight);
};
AdjMWGraph::AdjMWGraph(const int sz)
{
for(int i = 0; i < sz; i++)
{
for(int j = 0; j < sz; j++)
{
if(i == j) Edge[i][j] = 0;
else Edge[i][j] = MaxWeight;
}
}
numOfEdges = 0;
}
VerT AdjMWGraph::GetValue(const int i)
{
if(i < 0 || i > Vertices.ListSize())
{
cout <<"The 'i' is over the data!" <<endl;
exit(0);
}
return Vertices.GetData(i);
}
int AdjMWGraph::GetWeight(const int v1, const int v2)
{
if(v1 < 0 || v1 > Vertices.ListSize() || v2 < 0 || v2 > Vertices.ListSize())
{
cout <<"The 'v1' and 'v2' are over data!" <<endl;
exit(0);
}
return Edge[v1][v2];
}
void AdjMWGraph::InsertVertex(const VerT &vertex)
{
Vertices.Insert(vertex, Vertices.ListSize());
}
void AdjMWGraph::InsertEdge(const int v1, const int v2, int weight)
{
if(v1 < 0 || v1 > Vertices.ListSize() || v2 < 0 || v2 > Vertices.ListSize())
{
cout <<"The 'v1' and 'v2' are over data!" <<endl;
exit(0);
}
Edge[v1][v2] = weight;
numOfEdges++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -