Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. // zeroes to right
  2. void move_zeroes(vector<int> &arr) {
  3. int i = 0;
  4. for(auto el : arr) {
  5. if (el != 0) {
  6. arr[i++] = el;
  7. }
  8. }
  9. for(int k = i; k < arr.size())
  10. arr[k] = 0;
  11. }
  12.  
  13. // zeroes to left
  14. void move_zeroes(vector<int> &arr) {
  15. int i = arr.size() - 1;
  16. for(int el = arr.size(); el >= 0; el--) {
  17. if (arr[el] != 0)
  18. arr[i--] = arr[el];
  19. }
  20. for(int k = i; k >= 0; --k)
  21. arr[k] = 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement