归并排序,逆序数

写了个模板类,指针 a为被排序,b为tmp 返回逆序数,调用时候Merge.sort(a,b,n);

#define ll long long
template
class Merge {
public:
    T *a,*b;
    int n;
    ll num;
    ll sort(T *a1,T *b1,int n1){
        a=a1;b=b1;n=n1;
        num=0;
        divide(0,n-1);
        return num;
    }
    void divide(int l,int r){
        if(r>l){
            int mid=(l+r)>>1;
            divide(l,mid);
            divide(mid+1,r);
            merge(l,r);
        }
    }
    void merge(int l,int r){
        int mid=(l+r)>>1;
        int lpoint=l,rpoint=mid+1;
        int point=l;
        while(lpoint<=mid&&rpoint<=r){
            if(a[rpoint]


你可能感兴趣的:(模板,分治,归并排序+模板类)