Implementation of merge sort

时间:2016-10-20 12:51:00

标签: c

I need help with my implementation of merge sort in C.

My program generates a random array and display the execution time of sorts. My other sort work well but starting from 2000 Elements sorted my program stops.

I dont know why, please can you look at my implementation.

void Interclassement(TABLEAU t, int nbelts, int m, int n) {

    TABLEAU S = recopie( t, nbelts);
    int i, j, k;

    i = m;
    j = ((m+n)/2) +1;
    k = m;

    while (i <= (m+n)/2  && j <= n) {
        if (t[i] <= t[j]) {
            S[k] = t[i];
            i++;
        }
        else {
            S[k] = t[j];
            j++;
        }
        k++;
    }

    while (i <= (m+n)/2 ) {
        S[k]= t[i];
        i++;
        k++;
    }

    for (i=1; i < k-1 ; i++) {
        t[i]=S[i];
    }
}

void triParFusion(TABLEAU t, int nbelts, int m, int n){
    if (m < n) {
        triParFusion(t, nbelts, m, (m+n)/2 );
        triParFusion(t, nbelts, ((m+n)/2) +1, n);
        Interclassement(t, nbelts, m, n);
    }
} 

0 个答案:

没有答案