@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullArraysWithTwoPointers() { moveZeros.moveUsingTwoPointers(null); }
public void moveUsingTwoPointers(int[] array) { validateArray(array); int left = 0; int right = array.length - 1; while (left < right) { if (array[left] == 0 && array[right] != 0) { swap(array, left, right); } if (array[left] != 0) { left++; } if (array[right] == 0) { right--; } } }
MoveZerosInArray { public void moveUsingTwoPointers(int[] array) { validateArray(array); int left = 0; int right = array.length - 1; while (left < right) { if (array[left] == 0 && array[right] != 0) { swap(array, left, right); } if (array[left] != 0) { left++; } if (array[right] == 0) { right--; } } } }
MoveZerosInArray { public void moveUsingTwoPointers(int[] array) { validateArray(array); int left = 0; int right = array.length - 1; while (left < right) { if (array[left] == 0 && array[right] != 0) { swap(array, left, right); } if (array[left] != 0) { left++; } if (array[right] == 0) { right--; } } }  }
MoveZerosInArray { public void moveUsingTwoPointers(int[] array) { validateArray(array); int left = 0; int right = array.length - 1; while (left < right) { if (array[left] == 0 && array[right] != 0) { swap(array, left, right); } if (array[left] != 0) { left++; } if (array[right] == 0) { right--; } } }  void moveSorting(int[] array); void moveUsingTwoPointers(int[] array); }
MoveZerosInArray { public void moveUsingTwoPointers(int[] array) { validateArray(array); int left = 0; int right = array.length - 1; while (left < right) { if (array[left] == 0 && array[right] != 0) { swap(array, left, right); } if (array[left] != 0) { left++; } if (array[right] == 0) { right--; } } }  void moveSorting(int[] array); void moveUsingTwoPointers(int[] array);  }