I keep getting this error for the code below.
Upon reading this, I believed my error to be the it++
in my for loop, which I tried replacing with next(it, 1)
but it didn't solve my problem.
My question is, is the iterator the one giving me the issue here?
#include <iostream>
#include <vector>
#include <stack>
#include <set>
using namespace std;
struct Node
{
char vertex;
set<char> adjacent;
};
class Graph
{
public:
Graph() {};
~Graph() {};
void addEdge(char a, char b)
{
Node newV;
set<char> temp;
set<Node>::iterator n;
if (inGraph(a) && !inGraph(b)) {
for (it = nodes.begin(); it != nodes.end(); it++)
{
if (it->vertex == a)
{
temp = it->adjacent;
temp.insert(b);
newV.vertex = b;
nodes.insert(newV);
n = nodes.find(newV);
temp = n->adjacent;
temp.insert(a);
}
}
}
};
bool inGraph(char a) { return false; };
bool existingEdge(char a, char b) { return false; };
private:
set<Node> nodes;
set<Node>::iterator it;
set<char>::iterator it2;
};
int main()
{
return 0;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…