Could you help me with MergeSort?

1

I'm having trouble compiling the MergeSort sorting method.

#include <stdio.h>
#define TAM 10

void intercalar(int vet[],int aux[],int ini1, int ini2,int fim2) {
    int in1=ini1,in2=ini2,fim1=in2-1,au=0,i;
    while(in1<=fim1 && in2<=fim2) {
        if (vet[in1]<vet[in2]) {
            aux[au++] = vet[in1++];
        } else {
            aux[au++] = vet[in2++];
        }
    }
    while(in1<=fim1) {
        aux[au++] = vet[in1++];
    }
    while(in2<=fim2) {
        aux[au++] = vet[in2++];
    }
    for(i=0;i<au;i++) {
        vet[i+ini1]=aux[i];
    }
}

void Merge(int vet[], int aux[],int esq, int dir){
    int meio,i;
    if(esq<dir)
    {
        meio=(esq+dir)/2;
        Merge(vet,aux,esq,meio);
        Merge(vet,aux,meio+1,dir);
        intercalar(vet,aux,esq,meio+1,dir);  
    }
}

int main() {
    int vet[TAM], i, aux, n;          
    printf("Informe os numeros a serem ordenados: \n");
    for(i=0;i<TAM;i++)
        scanf("%d",&vet[i]);

    Merge(vet,aux,0,9);
    for(i=0;i<10;i++)
        printf("%d\t",vet[i]);

    return 0;
}
    
asked by anonymous 15.11.2016 / 05:58

1 answer

4

gcc itself points out the error:

  

test.c: In function 'main': teste.c: 41: 15: warning: passing argument   2 of 'Merge' makes pointer from integer without a cast   [-Wint-conversion]

 Merge(vet,aux,0,9);

Declaring aux as aux[TAM] , it sorts correctly.

    
15.11.2016 / 08:46