我正在编写一个带加权边的相邻的基于列表的图 . 我的目标是实现一个图来测试Djikstra的最短路径算法 . 我在实现removeEdge功能时遇到了麻烦 . 我查看了构建消息,但我不知道下面的错误是什么 .
在下面这个之前有一些警告但是它们很小,因为它编译并运行正常 .
c:\ program files(x86)\ codeblocks \ mingw \ bin .. \ lib \ gcc \ mingw32 \ 4.7.1 \ include \ c \ bits \ list.tcc ||实例化'void std :: list <_Tp ,_Alloc> :: remove(const value_type&)[with _Tp = Edge; _Alloc = std :: allocator; std :: list <_Tp,_Alloc> :: value_type = Edge]':|
这是生成的错误 .
c:\ program files(x86)\ codeblocks \ mingw \ bin .. \ lib \ gcc \ mingw32 \ 4.7.1 \ include \ c \ bits \ list.tcc | 249 |错误:不匹配'operator =='在'__first.std :: _ List_iterator <_Tp> :: operator *()== __value'|
现在,代码:
#ifndef WEIGHTED_ADJACENT_LIST_GRAPH_H
#define WEIGHTED_ADJACENT_LIST_GRAPH_H
#include <list>
#include <forward_list>
#include <stack>
#include <string>
using namespace std;
typedef int Weight;
class Edge;
class Vertex {
friend class Edge;
int num;
string name;
public:
Vertex();
Vertex(int n, string v_name){
num = n;
name = v_name;
}
int getNum() const{
return num;
}
string getName() const{
return name;
}
void setNum(int new_num){
num = new_num;
}
void setName(string new_name){
name = new_name;
}
};
class Edge {
Weight weight;
Vertex src;
Vertex dest;
public:
Edge();
Edge(Vertex s, Vertex d, Weight w):src(s), dest(d),weight(w){}
/*
Edge(Vertex s, Vertex d, Weight w){
src = s;
dest = d;
weight = w;
}
*/
Weight getWeight() const{
return weight;
}
int getSrcNum() const{
return src.num;
}
int getDestNum() const{
return dest.num;
}
};
class AdjacentList{
int num_Vertices;
list<Edge> *adj;
public:
AdjacentList();
AdjacentList(int n){
num_Vertices = n;
}
void addEdge(Vertex &i, Edge &j){
adj[i.getNum()].push_back(j);
}
void removeEdge(Vertex &i, Edge j){
if(!adj[i.getNum()].empty())
{
adj[i.getNum()].remove(j);
}
else{
cerr<<"Adjacent list underflow in removeEdge function"<<endl;
}
}
};
#endif
请注意,此图表不完整 . 那里仍然需要实现很多功能 . 有谁知道这个数据结构代码有什么问题?
1 回答
你还没有为
Edge
提供一个operator==
,我不知道你究竟想要指定哪个Edge
是相同的但你需要在使用remove
之前定义类似下面的内容