Hello i am trying to remove all arcs with a node(from an adjacency list) using the refresh funtion. i am getting a segmentation fault. can someone please help me?
void refresh(list<int> &a,int node)
{
//adj is the global adjacency list
list<int>::iterator it;
bool flag;
for(int j=0;j<TOTAL;j++)//TOTAL is number of nodes
{
flag=false;
for(it=adj[j].begin();it!=adj[j].end();++it)
{
int aa=(*it);//just added to help me on debugging
if( (*it)==node )
{
if(adj[j].size()==1){adj[j].clear();flag=true;break;}//i thought that maybe that was the problem when it was the last element and then it went to ++it
adj[j].erase(it);flag=true;}
elseif( ( (*it)!=node )&&(visited[(*it)-1]==0) )
{flag=false;
break;}
if(adj[j].empty()){break;}
}
if(flag){ a.push_back(j+1);}
}
}