#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void mergesort_(int a[], int b[], int l, int r);
void mergesort(int a[], int n);
void mergesort_(int a[], int b[], int l, int r) {
int c;
int i;
int j;
int k;
int n;
if (l >= r) {
return;
}
c = ((r - l) >> 1) + l;
mergesort_(a, b, l, c);
mergesort_(a, b, c + 1, r);
j = 0;
for (i = l; i <= c; i++) {
b[j] = a[i];
j++;
}
i = 0;
k = c + 1;
n = l;
while (k <= r) {
if (j <= i) {
return;
}
if (b[i] <= a[k]) {
a[n] = b[i];
n++;
i++;
} else {
a[n] = a[k];
n++;
k++;
}
}
while (i < j) {
a[n] = b[i];
n++;
i++;
}
}
void mergesort(int a[], int n) {
int *b
= calloc(n
>> 1, sizeof(int)); mergesort_(a, b, 0, n - 1);
}
int main(void) {
FILE *fin;
char buf[256];
char *token;
int nums[10];
int i;
fin
= fopen("numbers.dat", "r");
for (i = 0; i < 10; i++) {
}
mergesort(nums, 10);
for (i = 0; i < 10; i++) {
}
return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RkbGliLmg+CiNpbmNsdWRlPHN0cmluZy5oPgoKdm9pZCBtZXJnZXNvcnRfKGludCBhW10sIGludCBiW10sIGludCBsLCBpbnQgcik7CnZvaWQgbWVyZ2Vzb3J0KGludCBhW10sIGludCBuKTsKCnZvaWQgbWVyZ2Vzb3J0XyhpbnQgYVtdLCBpbnQgYltdLCBpbnQgbCwgaW50IHIpIHsKCWludCBjOwoJaW50IGk7CglpbnQgajsKCWludCBrOwoJaW50IG47CgkKCWlmIChsID49IHIpIHsKCQlyZXR1cm47Cgl9CgoJYyA9ICgociAtIGwpID4+IDEpICsgbDsKCW1lcmdlc29ydF8oYSwgYiwgbCwgYyk7CgltZXJnZXNvcnRfKGEsIGIsIGMgKyAxLCByKTsKCQoJaiA9IDA7Cglmb3IgKGkgPSBsOyBpIDw9IGM7IGkrKykgewoJCWJbal0gPSBhW2ldOwoJCWorKzsKCX0KCQoJaSA9ID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