Could you help me with Mergesort?

Asked

Viewed 74 times

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;
}
  • This question has 4 votes to close as not clear enough. However, when I saw Emoon’s answer, I came to the conclusion that the question is valid, although it needs some edits.

1 answer

4

gcc itself points out the error:

test. c: In Function ːmain': test. 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], he orders correctly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.