merge sort
稳定,
1.如果元素的个数为奇数
mid = len/2;
i=0;
j=mid+1;
k=0;
while(i<=mid && j<len){
if (a[i]<=a[j])
{
tmp[k]=a[i];
i++;
k++
}
else
{
tmp[k] = a[j];
j++;
k++;
}
}
while(i<=mid) tmp[k++]=a[i++];
while(j<len) tmp[k++] = a[j++];
稳定,
1.如果元素的个数为奇数
mid = len/2;
i=0;
j=mid+1;
k=0;
while(i<=mid && j<len){
if (a[i]<=a[j])
{
tmp[k]=a[i];
i++;
k++
}
else
{
tmp[k] = a[j];
j++;
k++;
}
}
while(i<=mid) tmp[k++]=a[i++];
while(j<len) tmp[k++] = a[j++];