title: Merge sort not working
body: <p>I have been working on merge sort and I have written some code for it but it is not working as per the given algorithm. I exactly did according to the algorithm but seems like something is wrong. Please anyone let me know whats wrong. </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main(){
      int a[] = {5, 3, 2, 4, 9, 1, 11, 6, 10};
      mergeSort(a, 0, sizeof(a)/ sizeof(int));
      printArray(a);
  }
  
  void mergeSort(int a[], int low, int high){
      int med;
      if(high - low &gt; 1){
          med = (high - low) / 2 + low;
          mergeSort(a, low, med);
          mergeSort(a, med+1, high);
          merge(a, low, med, high);
      }
  }
  void printArray(int a[]){
      int i;
      for(i = 0; i &lt; 9; i++){
          printf("%d ", a[i]);
      }
      printf("\n");
  }
  void merge(int a[], int low, int med, int high){
      int i = 0, j = 0, k = low;
      int a1[9];
      int a2[9];
      for(i = 0; i &lt; med; i++){
          a1[i] = a[i];
      }
  
      for(i = med; i &lt; high; i++){
          a2[i] = a[i];
      }
  
      while(i &lt; high - med &amp;&amp; j &lt; med - low){
          if(a1[i] &lt;= a2[j]){
              a[k] = a1[i];
              i++;
          }else{
              a[k] = a2[j];
              j++;
          }
      }
  
      while(i &lt; high - med){
          a[k] = a1[i];
          i++;
      }
  
      while(j &lt; med - low){
          a[k] = a2[j];
          j++;
      }
  
  }
  </code></pre>
  
  <p>Algorithm : <a href="http://i.stack.imgur.com/f73Zi.jpg" rel="nofollow">http://i.stack.imgur.com/f73Zi.jpg</a></p>