title: Recursive Merge Sort C++
body: <p>I want to write a recursive merge sort program in C++. The problem is, I don't know how to get the base case idea working recursively. Can anybody please tell me what would be the base case for <code>Merg Function()</code>, <code>Split Function()</code> and <code>MergSort()</code> function. I would be thankful to you.  </p>
  
  <pre><code>void Merg(int A[], int s1, int e1, int s2, int e2)
  {
     int B[8];
     int i=0;
  
     while (A[s1] &lt; A[s2])
        B[i] = B[s1];
        i++;
        s1++;
  
        if (s1 == e1)
        {
           B[i] = A[s2];
           i++;
           s2++;
        }
  
     while (A[s2] &lt; A[s1])
        B[i] = B[s2];
        i++;
        s2++;
  
        if (s2 == e2)
        {
           B[i] = A[s1];
           i++;
           s1++;
        }
  }
  
  void Split(int A[], int s, int e)
  {
     int mid = (s+e)/2;
  
     if (s &lt; e &amp;&amp; mid != 0)
     {   
        Split(A, s, mid);
        Split(A, mid+1, e);   
     }
     Merg(A, s, mid, mid+1, e);
  }
  
  int main()
  {
     int A[8] = {10,4,8,12,11,2,7,5};
  
     Split(A, 0, 7);
  
     return 0;
  }
  </code></pre>