Seeking to reverse merge sort template (to be continued)

Seeking to reverse merge sort topics (continually updated)

\ (1. \) \ (Ultra \) \ (Quicksort \) (need to read this blog post code)

Seeking to merge sort in reverse order

Details: parameter passing three, left, center, right three - point, taking note endpoint total and about half of each operation terminal; return condition is about equal to the endpoints, at this time do not sort.

\(View\) \(Code\)

void msort(int l,int mid,int r)
{
    if(l==r)
        return;
    msort(l,(l+mid)>>1,mid);
    msort(mid+1,(r+mid+1)>>1,r);
    int i=l,j=mid+1;
    for(register int k=l;k<=r;k++)
    {
        if(j>r||(i<=mid&&a[i]<a[j]))
            b[k]=a[i++];
        else
        {
            ans+=mid-i+1;
            b[k]=a[j++];
        }
    }
    for(register int k=l;k<=r;k++)
        a[k]=b[k];
}

Guess you like

Origin www.cnblogs.com/Peter0701/p/11247332.html