Recursive binary search, but this error appears:"expected Primary-Expression before 'int'"

Asked

Viewed 40 times

-2

#include <stdio.h>
#include <stdlib.h>

//Funcao para busca binaria com recursividade
int BuscaBinariaR(int vetor[10], int inicio,int fim, int x) {

    int meio = (inicio+fim)/2;


    if(inicio>fim)

        return (-1);

    else if(vetor[meio]==x)

        return (meio);

    else if(vetor[meio]>x)

        return BuscaBinariaR(vetor,inicio,meio-1,x);

    else
        return BuscaBinariaR(vetor,meio+1,fim,x);

}


int main () {

//Criando um vetor para teste
    int vetor[10],i,x;  
    BuscaBinariaR(int vetor[10],0,9,int x);

//Preenchendo o vetor   
    for(i=0; i<10; i++) {
    printf(" Digite um numero: ");
    scanf("%d", &vetor[i]);
    }

    printf("Qual numero deseja buscar: ");
    scanf("%d",x);

return 0;
}

1 answer

1

When you will call a function you cannot declare the variables there as you do with the parameters. Do:

BuscaBinariaR(vetor, 0, 9, x);

I put in the Github for future reference.

He looks like he has other problems, but this one solves it. For example, this call does not seem to be in the right place.

Browser other questions tagged

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