C++ Merge Sort without sentinal
<p>If I use the merge sort code with 
10,9,8,7,6,5,4,3,2,1 as input, the output is
2,3,4,5,6,7,9,10,8,1. 
I don't know where I am making a mistake. I tried to use <code>printf</code> to find where I am going wrong but could not locate it. Can you guys help me out?</p>

<pre><code>void merge_normal(Item * A, int p, int q, int r)
    {
        int i = 0;
        int j = q;
        int k = 0;
        int* myTempArray = new int[r];
        cout&lt;&lt;"value of i is "&lt;&lt; i &lt;&lt;" j is "&lt;&lt; j &lt;&lt;" k is "&lt;&lt;k;
        cout&lt;&lt;endl;
        while (i &lt; q &amp;&amp; j &lt; r) {
            if (A[i] &lt; A[j]) {
                cout&lt;&lt;"value of A[i] is "&lt;&lt; A[i] &lt;&lt; " A[j] is "&lt;&lt; A[j];
                cout&lt;&lt;endl;
                myTempArray[k] = A[i];
                ++i;
            } else {
                myTempArray[k] = A[j];
                ++j;
            }
            ++k;
        }

        while (i &lt; q) {
            cout&lt;&lt;"while i &lt; q "&lt;&lt; myTempArray[k] &lt;&lt; " = "&lt;&lt; A[i];
            cout&lt;&lt;endl;
            myTempArray[k] = A[i];
            ++i;
            ++k;
        }

        while (j &lt; r) {
            cout&lt;&lt;"while j &lt; r "&lt;&lt; myTempArray[k] &lt;&lt; " = "&lt;&lt; A[j];
            cout&lt;&lt;endl;
                    myTempArray[k] = A[j];
                    ++j;
                    ++k;
        }

        for (int index = 0; index &lt; r; ++index) 
        {
            A[index] = myTempArray[index];
            cout&lt;&lt;" for loop of copy "&lt;&lt; A[index] &lt;&lt; " = "&lt;&lt; myTempArray[index];
            cout&lt;&lt;endl;
        }

        delete [] myTempArray;
    }

    void mergesort_normal(Item * A, int p, int r)
    {
            int q;
        if(p&lt;r)
        {
            q = (p+r)/2;
            mergesort_normal(A,p,q);
            mergesort_normal(A,q+1,r);
            merge_normal(A,p,q,r);
        }
    }
</code></pre>
