void merge_sort(int A[], int l, int r)
{
if(l>=r) return;
int mid = l+r>>1;
merge_sort(A,l,mid), merge_sort(A,mid+1,r);
int i = l, j = mid+1, k=0; //有3个索引
//有两段数组,一个是l ~ mid,另一个是mid+1 ~ r;
//k记录新数组
while(i<=mid && j<=r) //记得先while循环,再if比较
{
if(A[i]<A[j]) tmp[k++] = A[i++];
else tmp[k++] = A[j++];
}
while(i<=mid) tmp[k++] = A[i++];
while(j<=r) tmp[k++] = A[j++];
for(int i=l, k=0; i<=r; i ++) //有2个索引
{
A[i] = tmp[k++];
}
}