我想实现图形ADT在C++中这里是代码实现图形ADT在C++中
#include <iostream>
using namespace std;
struct Edge{
int v,w;
Edge(int t=-1,int k=-1):v(t),w(k){}
};
class Graph {
public:
Graph(int,bool);
~Graph();
int V() const;
int E() const;
bool directed() const;
int remove(Edge);
int insert(Edge);
bool edge(int,int);
class AdjIterator{
public:
AdjIterator(const Graph&,int);
int beg();
int nxt();
bool end();
};
};
int main(){
return 0;
}
有多好是根据代码性能的这种实现的? 编辑: 我已经加入此代码
template<class Graph>
vector<Edge> edge(Graph& G){
int E=0;
vector<Edge>a(G.E());
for (int v=0;v<G.V();v++){
typename Graph::AdjIterator A(G,v);
for (int w=A.beg();w!=A.end();w=A.nxt())
if (G.directed() || v<w)
a[E++]=Edge(v,w);
}
return a;
}
@ user444288:我想,您需要描述更多或为我们添加更多代码来检查它的性能。 – bjskishore123 2010-09-18 10:46:04