写邻接列表图时出现未知错误
Unknown Error While Writing An Adjacent List Graph
我正在编写一个带加权边的相邻列表图。我的目标是实现一个图来测试Djikstra的最短路径算法。当我实现removeEdge函数时,我感到很失望。我查看了构建消息,但我不知道下面的错误是关于什么的。
在下面这个之前有一些警告,但它们是次要的,因为它编译和运行正常。
c:program files (x86)codeblocksmingwbin..libgccmingw324.7.1includec++bitslist。tcc||在实例化'void std::list<_Tp, _Alloc>::remove(const value_type&) [with _Tp = Edge;_Alloc = std::allocator;std:: list<_Tp _Alloc>:: value_type =]"边缘:|
这是生成的错误。
现在,代码:c:program files (x86)codeblocksmingwbin..libgccmingw324.7.1includec++bitslist。太极拳| 249 |错误:无法与"运算符= ="__first.std: _List_iterator<_Tp>::操作符* ()= = __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
请注意这张图是不完整的。许多功能仍然需要在那里实现。有人知道这个数据结构代码有什么问题吗?
您还没有为Edge
提供operator==
,我不知道您究竟想要如何指定哪些Edge
s是相等的,但是在使用remove
bool operator==(Edge const& lhs, Edge const& rhs)
{
return
lhs.getWeight() == rhs.getWeight() &&
lhs.getSrcNum() == rhs.getSrcNum() &&
lhs.getDestNum() == rhs.getDestNum();
}
相关文章:
- 双链表的擦除值函数,未知错误
- 未知C++错误:致命错误:glibc检测到无效的stdio句柄
- 带有unique_ptr的通用单链表,MS visual studio C++中存在未知错误
- 在最坏的情况下试验快速排序.它运行良好,但在最坏的情况下发生未知错误.我想
- C++ [] 重载未知错误
- 打电话时返回未知错误
- C 包括文件会导致未知错误
- Qtcpserver 仅在调试器下在侦听函数上返回未知错误
- std::p romise<void> 抛出未知错误,除非调用睡眠
- 如何在将我的 QT 应用程序交叉编译为 raspberry-pi3 时修复未知错误
- 使用reinterpret_cast的未知错误
- 如何修复QFile打开错误(未知错误),即使文件存在
- 使用c++特征库时出现未知错误
- 使用特征库的 mingw 出现未知错误
- CUDA 未知错误后 cuBLAS 调用
- 未知错误,调试器只给我一个内存地址
- 在子类之外实现函数导致未知错误
- 影响格雷厄姆查找凸包算法的未知错误
- 未知错误(-1000)执行cl_command_ndrange_kernel
- QT NetworkAccessManager未知错误