类定义我写在这了:
#include<iostream>
#include<fstream>
using namespace std;
typedef int* Edge;
class Graph
{
public:
int* matrix; //the adjacent matrix
int numVertex; //number of vertices
int numEdge; //number of edges
bool Mark; //the mark array
public:
Graph(); //Constructor
~Graph(){}; //Destructor
int n(); //return number of vertices
int e(); //return number of edges
Edge first(int); //get the first edge of a vertex
bool isEdge(Edge); //true if this is an edge
Edge next(Edge); //get next edge of a vertex
int v1(Edge); //get the vertex of the edge comes from
int v2(Edge); //get the vertex of the edge goes to
int weight(int,int); //get the weight of the edge(two vertices)
int weight(Edge); //get the weight of the edge(one edge)
};
下面我用伪码来表示我的想法:
for (int i=0;!文件尾;i++)
begin
文件中的数>>matrix[i]
char ch
数之间的空格>>ch
end
基本的想法就是这样了,但在具体的实践当中,总是有问题。