void mergeInt(int v[], int inicio, int fim, int aux[]) {
int meio = (inicio + fim) / 2;
int i = inicio;
int j = meio + 1;
int k = 0;
while (i <= meio || j <= fim) {
if (i <= meio && (j > fim || v[i] < v[j])) {
aux[k] = v[i];
i++;
} else {
aux[k] = v[j];
j++;
}
k++;
}
}
void mergeSortInt(int v[], int inicio, int fim, int aux[]) {
int meio = (inicio + fim) / 2;
if (inicio < fim) {
mergeSortInt(v, inicio, meio, aux);
mergeSortInt(v, meio + 1, fim, aux);
mergeInt(v, inicio, fim, aux);
for (int l = 0; l < fim - inicio + 1; l++) {
v[inicio + l] = aux[l];
}
}
}
void mergeSort(int v[], int tamanho) {
int *aux
= malloc(sizeof(int) * tamanho
); mergeSortInt(v, 0, tamanho, aux);
}
int main() {
int a[] = {10, 2, 7, 1, 4, 9, 3, 8, 0, 5, 6};
mergeSort(a, 11);
for (int i = 0; i < 11; i++) {
}
}
dm9pZCBtZXJnZUludChpbnQgdltdLCBpbnQgaW5pY2lvLCBpbnQgZmltLCBpbnQgYXV4W10pIHsKICAgIGludCBtZWlvID0gKGluaWNpbyArIGZpbSkgLyAyOwogICAgaW50IGkgPSBpbmljaW87CiAgICBpbnQgaiA9IG1laW8gKyAxOwogICAgaW50IGsgPSAwOwogICAgd2hpbGUgKGkgPD0gbWVpbyB8fCBqIDw9IGZpbSkgewogICAgICAgIGlmIChpIDw9IG1laW8gJiYgKGogPiBmaW0gfHwgdltpXSA8IHZbal0pKSB7CiAgICAgICAgICAgIGF1eFtrXSA9IHZbaV07CiAgICAgICAgICAgIGkrKzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBhdXhba10gPSB2W2pdOwogICAgICAgICAgICBqKys7CiAgICAgICAgfQogICAgICAgIGsrKzsKICAgIH0KfQoKdm9pZCBtZXJnZVNvcnRJbnQoaW50IHZbXSwgaW50IGluaWNpbywgaW50IGZpbSwgaW50IGF1eFtdKSB7CiAgICBpbnQgbWVpbyA9IChpbmljaW8gKyBmaW0pIC8gMjsKCiAgICBpZiAoaW5pY2lvIDwgZmltKSB7CiAgICAgICAgbWVyZ2VTb3J0SW50KHYsIGluaWNpbywgbWVpbywgYXV4KTsKICAgICAgICBtZXJnZVNvcnRJbnQodiwgbWVpbyArIDEsIGZpbSwgYXV4KTsKICAgICAgICBtZXJnZUludCh2LCBpbmljaW8sIGZpbSwgYXV4KTsKCiAgICAgICAgZm9yIChpbnQgbCA9IDA7IGwgPCBmaW0gLSBpbmljaW8gKyAxOyBsKyspIHsKICAgICAgICAgICAgdltpbmljaW8gKyBsXSA9IGF1eFtsXTsKICAgICAgICB9CiAgICB9Cn0KCnZvaWQgbWVyZ2VTb3J0KGludCB2W10sIGludCB0YW1hbmhvKSB7CiAgICBpbnQgKmF1eCA9IG1hbGxvYyhzaXplb2YoaW50KSAqIHRhbWFuaG8pOwogICAgbWVyZ2VTb3J0SW50KHYsIDAsIHRhbWFuaG8sIGF1eCk7CiAgICBmcmVlKGF1eCk7Cn0KCmludCBtYWluKCkgewogICAgaW50IGFbXSA9IHsxMCwgMiwgNywgMSwgNCwgOSwgMywgOCwgMCwgNSwgNn07CiAgICBtZXJnZVNvcnQoYSwgMTEpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAxMTsgaSsrKSB7CiAgICAgICAgcHJpbnRmKCIlZCAiLCBhW2ldKTsKICAgIH0KfQ==