void mergeInt(int v[], int i, int meio, int j, int fim, int k, int aux[]) {
if (i <= meio && (j > fim || v[i] < v[j])) {
aux[k] = v[i];
mergeInt(v, i + 1, meio, j, fim, k + 1, aux);
} else if (j <= fim) {
aux[k] = v[j];
mergeInt(v, i, meio, j + 1, fim, k + 1, aux);
}
}
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, meio, meio + 1, fim, 0, 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++) {
}
}
dm9pZCBtZXJnZUludChpbnQgdltdLCBpbnQgaSwgaW50IG1laW8sIGludCBqLCBpbnQgZmltLCBpbnQgaywgaW50IGF1eFtdKSB7CiAgICBpZiAoaSA8PSBtZWlvICYmIChqID4gZmltIHx8IHZbaV0gPCB2W2pdKSkgewogICAgICAgIGF1eFtrXSA9IHZbaV07CiAgICAgICAgbWVyZ2VJbnQodiwgaSArIDEsIG1laW8sIGosIGZpbSwgayArIDEsIGF1eCk7CiAgICB9IGVsc2UgaWYgKGogPD0gZmltKSB7CiAgICAgICAgYXV4W2tdID0gdltqXTsKICAgICAgICBtZXJnZUludCh2LCBpLCBtZWlvLCBqICsgMSwgZmltLCBrICsgMSwgYXV4KTsKICAgIH0KfQoKdm9pZCBtZXJnZVNvcnRJbnQoaW50IHZbXSwgaW50IGluaWNpbywgaW50IGZpbSwgaW50IGF1eFtdKSB7CiAgICBpbnQgbWVpbyA9IChpbmljaW8gKyBmaW0pIC8gMjsKCiAgICBpZiAoaW5pY2lvIDwgZmltKSB7CiAgICAgICAgbWVyZ2VTb3J0SW50KHYsIGluaWNpbywgbWVpbywgYXV4KTsKICAgICAgICBtZXJnZVNvcnRJbnQodiwgbWVpbyArIDEsIGZpbSwgYXV4KTsKICAgICAgICBtZXJnZUludCh2LCBpbmljaW8sIG1laW8sIG1laW8gKyAxLCBmaW0sIDAsIGF1eCk7CgogICAgICAgIGZvciAoaW50IGwgPSAwOyBsIDwgZmltIC0gaW5pY2lvICsgMTsgbCsrKSB7CiAgICAgICAgICAgIHZbaW5pY2lvICsgbF0gPSBhdXhbbF07CiAgICAgICAgfQogICAgfQp9Cgp2b2lkIG1lcmdlU29ydChpbnQgdltdLCBpbnQgdGFtYW5obykgewogICAgaW50ICphdXggPSBtYWxsb2Moc2l6ZW9mKGludCkgKiB0YW1hbmhvKTsKICAgIG1lcmdlU29ydEludCh2LCAwLCB0YW1hbmhvLCBhdXgpOwogICAgZnJlZShhdXgpOwp9CgppbnQgbWFpbigpIHsKICAgIGludCBhW10gPSB7MTAsIDIsIDcsIDEsIDQsIDksIDMsIDgsIDAsIDUsIDZ9OwogICAgbWVyZ2VTb3J0KGEsIDExKTsKICAgIGZvciAoaW50IGkgPSAwOyBpIDwgMTE7IGkrKykgewogICAgICAgIHByaW50ZigiJWQgIiwgYVtpXSk7CiAgICB9Cn0=