int arr[] = {0,0,0,1,0,2,3,0,4,5,0,0,0};
int size = sizeof(arr)/sizeof(int);
int i = 0,j = 0;
while(i < size && j < size){
while(arr[i] != 0) i++;
j = i+1;
while(arr[j] == 0 && j < size) j++;
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;j++;
}
大概是这样,试了几个案例,应该没问题...吧