Я получаю ошибку сегментации при попытке вызвать метод addEdge(int, int)
. calling code
ниже. Кто-нибудь может помочь?
void addEdge(int i, int j)
{
if (i >= 0 && j > 0)
{
Node* whereto;
whereto = linkedAdjacencyList[i];
if(whereto != NULL) //the segmentation fault occurs here
{
while(whereto->adj != NULL)
{whereto = whereto->adj;}
whereto->adj = linkedAdjacencyList[j];
}
else{linkedAdjacencyList[i]->adj = linkedAdjacencyList[j];}
whereto = linkedAdjacencyList[j];
if(whereto != NULL)
{
while(whereto->adj != NULL)
{whereto = whereto->adj;}
whereto->adj = linkedAdjacencyList[i];
}
else{linkedAdjacencyList[j]->adj = linkedAdjacencyList[i];}
}
}
std::istream& operator>>(std::istream& in, UndirectedGraph& g)
{
int numVerticies;
in >> numVerticies;
g = UndirectedGraph(numVerticies);
int edges;
in >> edges;
g.edges = edges;
for(int i = 0; i < edges; i++)
{
int first;
int second;
in >> first >> second;
g.addEdge(first, second);
}
есть идеи?