64,676
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
template<typename T,typename E>
class MatrixGraph
{
T *VerticesList; //vertex table
E **Edge; //Adjacent matrix
friend istream& operator >>(istream& in,MatrixGraph<T,E>& G);
friend ostream& operator <<(ostream& out,MatrixGraph<T,E>& G);
public:
MatrixGraph(int sz=defaultVertices);
~MatrixGraph()
{
delete [] VerticesList;
delete [] Edge;
}
};
template<typename T,typename E>
MatrixGraph<T,E>::MatrixGraph(int sz)
{
maxVertices = sz;
numVertices = numEdges = 0;
VerticesList = new T[maxVertices]; //create array of vertex table
Edge = new int *[maxVertices]; //create array of AdjacentMatrix
for (int i=0;i<maxVertices;i++)
Edge[i] = new int[maxVertices];
for (int i=0;i<maxVertices;i++)
for (int j=0;j<maxVertices;j++)
Edge[i][j] = (i==j) ? 0 : maxWeight;
}
int main(void)
{
//MatrixGraph<int,int> AdjMatG(10);
return 0;
}