Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. // (WRONG)
  2. int x = v[i]; // the new v[i], that is
  3. v.erase(v.begin() + i);
  4. v.insert(
  5. std::upper_bound(v.begin() + i, v.end(), x),
  6. x
  7. )
  8.  
  9. int x = v[i]; // the new v[i], that is
  10. if (/* new v[i] is > old v[i] */) {
  11. size_t j = i + 1;
  12. while (v[j] < x && j < v.size()) {
  13. std::swap(v[j-1], v[j])
  14. j++;
  15. }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement