My code has no compilation error. It seems to have a runtime error. In the following piece of code, when the while loop is executed for the first time everything works fine. But on the second iteration, everything stops at "list::iterator k = (temp2->store).begin();". When I comment out the "list::iterator k ..." part everything works fine. The variables temp2 and temp2->store are not NULL or empty. The debugger gave the following message "Unhandled exception at 0x009bc0cf in project euler.exe: 0xC0000005: Access violation reading location 0xddddddf5".
struct edge
{ int end1, end2;
ptr_to_edge *ptr_end1, *ptr_end2;
edge *next, *l_chd, *r_chd;
edge(): next(NULL), l_chd(NULL), r_chd(NULL), ptr_end1(NULL), ptr_end2(NULL)
{ }
};
struct ptr_to_edge {
int flag, vertex;
list<edge*> store;
ptr_to_edge(): flag(1)
{ }
};
void parallel_reduction_step(ptr_to_edge *front, vector<edge> &a) {
list<edge*>::iterator next = (front->store).begin();
next++;
list<edge*>::iterator current = (front->store).begin();
list<edge*>::iterator last = (front->store).end();
--last;
while(current!= last) {
if(((*current)->end1 == (*next)->end1)&&((*current)->end2==(*next)->end2)) {
edge temp1;
temp1.end1 = (*current)->end1; temp1.end2 = (*current)->end2;
a.push_back(temp1);
ptr_to_edge *temp2;
if ((*current)->end1==front->vertex)
temp2 = (*current)->ptr_end2;
else
temp2 = (*current)->ptr_end1;
list<edge*>::iterator k = (temp2->store).begin();
current = (front->store).erase(j);
*current = &(a.back());
}
else current++;
next++;
}
};