Proszę o pomoc w znalezieniu błędu, komiplator wyrzuca błąd Segmentation Fault 11, gdb za to podpowiada:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000000
0x0000000100002ee8 in std::list<int, std::allocator<int> >::erase (this=0x1008044e8, __position={_M_node = 0x0}) at list.tcc:98
98 iterator __ret = iterator(__position._M_node->_M_next);
niestety nie jestem w stanie dojść w czym tkwi problem, prosiłbym kogoś bardziej doświadczonego o podpowiedź.
Graph.hpp:
#include <list>
#include <utility>
#include <vector>
using namespace std;
typedef int value; // depends on type of stored values
typedef list<int> edgesList;
typedef pair<value, edgesList> node;
class Graph { // adjacency list representation
private:
int vertices;
int edges;
node *Adj;
public:
Graph(string, int);
~Graph();
int getVertices();
int getEdges();
};
Graph.cpp:
#include "Graph.hpp"
#include <fstream>
#include <sstream>
Graph::Graph(string path, int _vertices) {
vertices = _vertices;
edges = 0;
Adj = new node[vertices + 1];
fstream data;
data.open(path.c_str(), ios::in);
value val;
int num;
int i = 1;
string line;
while (!data.eof()) {
getline(data, line);
istringstream sstream(line);
sstream >> val;
edgesList l;
while (sstream >> num) {
l.push_back(num);
++edges;
}
pair<value, edgesList> tmp;
tmp = make_pair(val, l);
Adj[i] = tmp;
++i;
}
data.close();
edges /= 2;
}
Graph::~Graph() {
delete[] Adj;
}
int Graph::getVertices() {
return vertices;
}
int Graph::getEdges() {
return edges;
}
Zapomniałem dodać, że graf jest dany w takim sposób, że pierwsza liczba w każdym wierszu oznacza numer wierzchołka a następne oznaczają sąsiadów, np:
1 4 5 3
2 4
3 1 5
4 1 2
5 1 3