You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The program also has an error in that the location of mid must be handled some other way, as the iterator to mid would be invalidated every time an insertion in the front half of the vector occurs -- though this program doesn't do it, it could be invalidated after any operation that changes the size of the container.
One way to handle this would be removing the need to access the mid iterator any time after the loop starts:
std::vector<int>::iterator iter = iv.begin();
for (std::vector<int>::size_type cnt = iv.size()/2; cnt != 0; --cnt) {
if (*iter == some_val) {
iter = iv.insert(iter, 2 * some_val);
++iter;
}
++iter;
}
The text was updated successfully, but these errors were encountered:
The program also has an error in that the location of mid must be handled some other way, as the iterator to mid would be invalidated every time an insertion in the front half of the vector occurs -- though this program doesn't do it, it could be invalidated after any operation that changes the size of the container.
One way to handle this would be removing the need to access the mid iterator any time after the loop starts:
The text was updated successfully, but these errors were encountered: