Reputation: 3
I have two structures
struct Edge{
int v1;
int v2;
int weigt;
Edge(int v1_tmp, int v2_tmp, int weight_tmp);
};
struct GraphList{
int V;
int E;
list<Edge>* mylist;
}
GraphList::GraphList(GrafMatrix* graph){
V=graph->V;
E=graph->E;
for (int i=0; i<V; i++){
for (int j=0; j<V; j++){
if (graph->matrix[i][j]==1) mylist[i].push_back( Edge(i+1, j+1, graf->weights[i][j]) );
}
}
}
What's wrong? When i=0
and j=1
, there's an error. I tried lista = new list<Krawedz>()
but it doesn't work. Any ideas?
Upvotes: 0
Views: 68
Reputation: 8787
You are dereferencing a pointer which was never allocated any space. Notice list<Edge>* mylist
. You should use new
as
mylist = new list<Edge>[k]; //declare an array of k list<Edge>.
Then you will be able to access mylist[0] ,...., mylist[k-1].
Upvotes: 2