​https://leetcode.com/problems/move-zeroes/​

Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.

For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].

Note:
You must do this in-place without making a copy of the array.
Minimize the total number of operations.

设置左右两个指针,分别为left、right,left指向数组未判断的元素,right指向最后一个未判断的元素,
使用while循环遍历每个未判断的元素,如果检测到0元素,将后面所有的未判断元素向前移动一个位置。

void moveZeroes(int* nums, int numsSize) {
int left, right;
int i;

left = 0;
right = numsSize - 1; // end's zero
while(left < right) {
if(nums[left] == 0) {// move zero to end of array
for(i = left + 1; i <= right; i++) {
nums[i - 1] = nums[i];
}

//
nums[right--] = 0;
}else {
left++;
}
}// end while
}