/****************************************************************/ /*** Mergsort ***/ /*** Rechnergestütztes Wissenschaftliches Rechnen ***/ /*** University of Goettingen, Germany 2004 ***/ /****************************************************************/ #include #include /** sorts 'n' integer numbers in the array 'a' in ascending **/ /** order using the mergsort algorithm **/ void mergesort(int n, int *a) { int *b,*c; /* two arrays */ int n1, n2; /* sizes of the two arrays */ int t, t1, t2; /* (loop) counters */ if(n<=1) /* at most one element ? */ return; /* nothing to do */ n1 = n/2; n2 = n-n1; /* calculate half sizes */ /* array a is distributed to b,c. Note: one could do it */ /* using one array alone, but yields less clear algorithm */ b = (int *) malloc(n1*sizeof(int)); c = (int *) malloc(n2*sizeof(int)); for(t=0; t