#include <bits/stdc++.h>
using namespace std;
void moveZeroes(vector<int>& nums) {
int j = 0, n = nums.size();
//move the non-zero elements to the front
for(int i = 0; i < n; i++){
if(nums[i] != 0){
nums[j++] = nums[i];
}
}
//fill the remaining right indices with zeros
for(int i = j; i < n; i++){
nums[i] = 0;
}
}
int main() {
int myints[] = {10, 0, 30, 0, 50, 60, 0, 80};
vector<int> v(myints, myints+8);
moveZeroes(v);
for(int i = 0; i < v.size(); i++){
cout << v[i] << " ";
}
cout << endl;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIG1vdmVaZXJvZXModmVjdG9yPGludD4mIG51bXMpIHsKICAgIGludCBqID0gMCwgbiA9IG51bXMuc2l6ZSgpOwogICAgLy9tb3ZlIHRoZSBub24temVybyBlbGVtZW50cyB0byB0aGUgZnJvbnQKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspewogICAgICAgIGlmKG51bXNbaV0gIT0gMCl7CiAgICAgICAgICAgIG51bXNbaisrXSA9IG51bXNbaV07CiAgICAgICAgfQogICAgfQogICAgLy9maWxsIHRoZSByZW1haW5pbmcgcmlnaHQgaW5kaWNlcyB3aXRoIHplcm9zCiAgICBmb3IoaW50IGkgPSBqOyBpIDwgbjsgaSsrKXsKICAgICAgICBudW1zW2ldID0gMDsKICAgIH0KfQogICAgCmludCBtYWluKCkgewoJaW50IG15aW50c1tdID0gezEwLCAwLCAzMCwgMCwgNTAsIDYwLCAwLCA4MH07Cgl2ZWN0b3I8aW50PiB2KG15aW50cywgbXlpbnRzKzgpOwoJbW92ZVplcm9lcyh2KTsKCWZvcihpbnQgaSA9IDA7IGkgPCB2LnNpemUoKTsgaSsrKXsKCQljb3V0IDw8IHZbaV0gPDwgIiAiOwoJfQoJY291dCA8PCBlbmRsOwoJcmV0dXJuIDA7Cn0=