I try to store all generated value by pushing the values into vector.
However I encountered a debug assertion message displaying:"Vector iterator is not incremental"
Then, i try to google for solution and found out that have to use erase or delete.
So i try to implement into my function..yet facing the same issue.
Any ideas?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void nearlystd_store(int val, vector<int> &aVec)//nearly sorted function
{
vector<int>::iterator Iter;// a vector
for (int i = 0; i < val; i ++)//generate from the start till desired nvalue
{
aVec.push_back(val - i);//push into this vector
}
partial_sort(aVec.begin(), aVec.begin() + (val / 2), aVec.end());//sort half in the vector
for (Iter = aVec.begin(); Iter != aVec.end(); ++Iter)//push sorted value
{
aVec.push_back(*Iter);
delete *Iter;
}
}
In the loop on lines 11 through 15, you are using push_back on aVec. push_back may invalidate existing iterators, after which the iterator will be "not incrementable."
It isn't clear exactly what you're trying to accomplish since, if this weren't undefined behavior, it would be an infinite loop.