Here you can find the source of swapZeros(int[] input, int zeroCount)
static void swapZeros(int[] input, int zeroCount)
//package com.java2s; //License from project: Apache License public class Main { static void swapZeros(int[] input, int zeroCount) { int inputLength = input.length; int nonZeroLength = inputLength - zeroCount; for (int i = 0; i < nonZeroLength; i++) { if (inputLength <= nonZeroLength) { break; }//from w w w. j a v a 2s .c om int element = input[i]; if (element == 0) { int temp = 0; while (temp == 0) { temp = input[--inputLength]; input[inputLength] = 0; } input[i] = temp; } } } }