Hi! I wrote a piece of code to delete some elements from an array. With deleting I'm saying: replacing the original values by 0. I don't know another way to keep the indices of the other elements at the same place. I can't just delete elements by placing them at the end and then creating a new array without the elements at the end, since then I'll end up with different indicies for the elements that I still need.
So my solution is like this:
Code:
//Step #3: Remove old edges from edgeslist and heap
int aantal = 0;
for(edge=0;edge<nbEdges;edge++) {
for (i=0; i<nbVertsCells[delVert]; i++) {
ver2 = vertsCells[delVert][i];
if( !fixed2[ver2] && ((EdgesList[edge][0] == delVert) && (EdgesList[edge][1] == ver2)) ) {
//Remove old Edges from the edgeslist
EdgesList[edge] = new unsigned int[2];
EdgesList[edge][0] = 0; //set elements to zero. Adding at the end in the future?
EdgesList[edge][1] = 0;
delEdge = edge;
//Remove old Edges from the Heap
heapRemoveEdgeValue(nbEdgesHeap, heapEdges, posEdges, errorCells2, delEdge);
delEdgeInd[aantal] = delEdge;
aantal++;
}
}
}
//Step #4: Add new edges to edgeslist
for(i=0;i<nbNewEdges;i++) {
//EdgesList[delEdgeInd[i]] = new unsigned int[2];
EdgesList[delEdgeInd[i]][0] = (unsigned int)FinalEdgesList[i][0];
EdgesList[delEdgeInd[i]][1] = (unsigned int)FinalEdgesList[i][1];
delete[] FinalEdgesList[i];
}
delete[] FinalEdgesList;
Unfortuantely this piece of code seems to bug a little, when testing it takes VERY long to pass this part. Is there something wrong with my approach? I just put som elements to zero and afterwoods I use these empty place to add new elements into it. Since nbNewEdges is smaller then the amount of zeros created, there'll always be some elements in EdgesList[][] who are still both zero.
Can anyone help me out with debugging this? There's not really an error or something, but like I said: I think there's a bottleneck in it...