Skip to main content
Java has zero-based arrays. Fix off-by-one bug.
Source Link
Davislor
  • 9.2k
  • 19
  • 39

If the filter does not need to be stable, you can use the following in-place algorithm:

Repeatedly find the index i of the first non-even element and the index j of the last even element. While i < j, swap the elements and repeat.

Truncate the array to j + 1 elements.

If the filter does not need to be stable, you can use the following in-place algorithm:

Repeatedly find the index i of the first non-even element and the index j of the last even element. While i < j, swap the elements and repeat.

Truncate the array to j elements.

If the filter does not need to be stable, you can use the following in-place algorithm:

Repeatedly find the index i of the first non-even element and the index j of the last even element. While i < j, swap the elements and repeat.

Truncate the array to j + 1 elements.

Source Link
Davislor
  • 9.2k
  • 19
  • 39

If the filter does not need to be stable, you can use the following in-place algorithm:

Repeatedly find the index i of the first non-even element and the index j of the last even element. While i < j, swap the elements and repeat.

Truncate the array to j elements.