图模型的相邻矩阵怎样才能高效率地读入C++程序

fanbin23 2002-08-31 10:09:53
我想通过文件的读入来完成,但怎样在读入的同时判断图中的点有多少个?怎样知道是否把所有的点都读完了,在循环过程中循环变量该如何控制?
...全文
29 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
fanbin23 2002-08-31
  • 打赏
  • 举报
回复
类定义我写在这了:
#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
基本的想法就是这样了,但在具体的实践当中,总是有问题。
blh 2002-08-31
  • 打赏
  • 举报
回复
能不能把你的算法书的清楚些,呵呵
fanbin23 2002-08-31
  • 打赏
  • 举报
回复
我是个菜鸟,觉得还不到用现成东西的时候。
lak47 2002-08-31
  • 打赏
  • 举报
回复
不用这会费事了,在boost库里有现成的

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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