title: Segregating an array for even and odd numbers
body: <p>I have implemented an algorithm to change an array so that all the even numbers are moved to the beginning of the array and the old numbers to the end of the array. Here is my program :-</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  void print(int arr[], int size) {
      for(int i=0;i&lt;size;i++) {
          cout&lt;&lt;arr[i]&lt;&lt;" ";
      }
      cout&lt;&lt;endl;
  }
  
  void segregate(int arr[], int size) {
      int l=0, h=size-1;
  
      while(l&lt;h) {
  
          while(!(arr[l]%2) &amp;&amp; l&lt;size) {
              l++;
          }
          while((arr[h]%2) &amp;&amp; h &gt;=0) {
              h--;
          }
          swap(arr[l], arr[h]);
      }
  }
  
  int main() {
  
      int arr[] = {1,2,3,4,5,6,7,8,9};
      int size = 9;
  
      print(arr,size);
  
      segregate(arr,size);
  
      print(arr,size);
  
      return 0;
  }
  </code></pre>
  
  <p>I don't get the expected result </p>
  
  <pre><code>1 2 3 4 5 6 7 8 9 
  8 2 6 5 4 3 7 1 9 
  </code></pre>
  
  <p>What am I missing?</p>