昏了!!菜鸟问题,请指教!!!

ascmvi 2005-12-20 08:42:24
用邻接矩阵表示的图的类的定义

const int MaxValue = ……;
const int MaxEdges = 50;
const int MaxVertices = 10;
template <class Type>
class Graph {
private:
Type VerticesList[MaxVertices];
float Edge[MaxVertices][MaxVertices];
int numberEdges;
int numberVertices;
int GetVertexPos ( const Type vertex ) {
for ( int i = 0; i < numberVertices; i++ )
if ( VerticesList[i] == Vertex ) return i;
return -1;
}
public:
Graph ( int sz = MaxEdges );
int GraphEmpty ( ) const
{ return numberVertices == 0 ||
numberEdges == 0; }
int GraphFull( ) const
{ return numberVertices == MaxVertices ||
numberEdges == MaxEdges; }
int NumberOfVertices ( )
{ return numberVertices; }
int NumberOfEdges ( )
{ return numberEdges; }
Type GetValue ( int i )
{ return i >= 0 && i <= numberVertices
? VerticesList[i] : NULL; }
float GetWeight ( int u, int v ) {
if (u != -1 && v != -1) return Edge[u][v];
else return 0;
}
int GetFirstNeighbor ( int v );
int GetNextNeighbor ( int v, int w );
void InsertVertex ( const Type vertex );
void InsertEdge ( int u, int v, float weight );
};
...全文
110 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
frankzch 2005-12-21
  • 打赏
  • 举报
回复
mmmcd 2005-12-21
  • 打赏
  • 举报
回复
float Edge[MaxVertices][MaxVertices];

数组下标范围是[0,MaxVertices-1]
-1在这范围外,要判断一下
Rick_ang 2005-12-21
  • 打赏
  • 举报
回复
用-1来代表顶点不存在吧,一定要两个顶点都存在才能返回权值
ascmvi 2005-12-20
  • 打赏
  • 举报
回复
其中:
float GetWeight ( int u, int v ) {
if (u != -1 && v != -1) return Edge[u][v];
else return 0;
}



if (u != -1 && v != -1) 是什么意思???????????
u!=-1&&v!=-1是什么意思??????????????


本程序出自 清华大学计算机系列教材 殷人昆 陶永雷 谢若阳 盛绚华 编著
数据结构(用面向对象方法与C++描述)

33,028

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧