I have a list from the stl called Clist. It has alot of items in it and one is a double called fVal. I want to insert new nodes in the list in ascending value according to the fVal. I have tried the following code and it works fine for up 8 nodes but after 9 nodes it breaks down and just inserts new nodes at the end of the list. Any comments would be very much appreciated.
int Ccounter = 0;
itC = Clist.begin();
while( Ccounter <= Clist.size())
{
//itC++;
Ctest = *itC;
itC++;
Ctest2 = *itC;
if((fx1 >= Ctest.fVal) && (fx1 <= Ctest2.fVal) )
{
Clist.insert(itC, X1);
Ccounter = Ccounter + Clist.size();
}
if(Ccounter == 0 && fx1 <= Ctest.fVal)
{
Clist.push_front(X1);
Ccounter = Ccounter+Clist.size()+1;
}
if(itC == Clist.end())
{
Clist.push_back(X1);
Ccounter = Ccounter+Clist.size();
}
Ccounter++;
itC++;
}