title: Could this algorithm be made better?
body: <p>I have a question, in one of the algorithms, I had written, to seperate out, all the even numbers to the left and odd numbers to the right. </p>
  
  <p>Example: Input:</p>
  
  <blockquote>
    <p>{ 12, 10, 52, 57, 14, 91, 34, 100, 245, 78, 91, 32, 354, 80, 13, 67, 65 }</p>
  </blockquote>
  
  <p>Output:</p>
  
  <blockquote>
    <p>{12,10,52,80,14,354,34,100,32,78,91,245,91,57,13,67,65}</p>
  </blockquote>
  
  <p>Below is the algorithm</p>
  
  <pre><code>public int[] sortEvenAndOdd(int[] combinedArray) {
    int endPointer = combinedArray.length - 1;
    int startPointer = 0;
    for (int i = endPointer; i &gt;= startPointer; i--) {
      if (combinedArray[i] % 2 == 0) {
        if (combinedArray[startPointer] % 2 != 0) {
          int temp = combinedArray[i];
          combinedArray[i] = combinedArray[startPointer];
          combinedArray[startPointer] = temp;
          startPointer = startPointer + 1;
        } else {
          while (combinedArray[startPointer] % 2 == 0 &amp;&amp;
            (startPointer != i)) {
            startPointer = startPointer + 1;
          }
          int temp = combinedArray[i];
          combinedArray[i] = combinedArray[startPointer];
          combinedArray[startPointer] = temp;
          startPointer = startPointer + 1;
        }
      }
    }
    return combinedArray;
  }
  </code></pre>
  
  <p>Anybody, have any suggestions, for it make it to O(n) or better ?</p>