Skip to content

Commit

Permalink
fixed ex9_22.cpp again.
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Jun 20, 2015
1 parent f96a68e commit 276deba
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ch09/ex9_22.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ using std::vector;

void insertDoubleValue(vector<int> &iv, int some_val)
{
auto iter = iv.begin(), mid = iv.begin() + iv.size()/2;
auto cursor = iv.size() / 2;
auto iter = iv.begin(), mid = iv.begin() + cursor;
while (iter != mid) {
if (*iter == some_val) {
iter = iv.insert(iter, 2 * some_val);
++iter;
mid = iv.begin() + iv.size()/2;
++iter; ++cursor;
mid = iv.begin() + cursor;
}
++iter;
}
Expand All @@ -24,7 +25,7 @@ void print(const vector<int> &iv)

int main()
{
vector<int> iv = {1, 2, 1, 3, 1, 4, 1, 5};
vector<int> iv = {1, 1, 1, 1, 1, 7, 1, 9};
insertDoubleValue(iv, 1);
print(iv);
}

0 comments on commit 276deba

Please sign in to comment.