Dev - C++ - BUSQUEDA BINARIA

 
Vista:
sin imagen de perfil

BUSQUEDA BINARIA

Publicado por Rene (1 intervención) el 05/07/2021 18:59:18
hola amigos tengo un problema me esta dando error en los ultimos else y no encuentro errores me pueden ayudar?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
#define dimension 3
main()
{
	int indice,j,valor;
	int pos_menor,alto,bajo,central;
	float menor, AUX;
	float arreglo[dimension];
 
 
	/* lee el vector*/
	for (indice=0;indice<dimension;indice++)
	{
		printf("arrglo[%i]= ",indice);
		scanf("%f", &arreglo[indice]);
	}
	/* ordena por seleccion*/
	for (indice;indice<dimension;indice++)
	{
		menor=arreglo[indice];
		pos_menor=indice;
		for(j=indice+1;j<dimension;j++)
		{
			if (menor>arreglo[j])
			{
				menor=arreglo[j];
				pos_menor=j;
 
			}
		}
		AUX=arreglo[indice];
		arreglo[indice]=arreglo[pos_menor];
		arreglo[pos_menor]=AUX;
	}
	/* imprime el valor*/
	for (indice=0;indice<dimension;indice++)
	{
		printf("arreglo[%i]=%f\n",indice,arreglo[indice]);
	}
	printf("\n que valor desea buscar? ");
	scanf("%f", &valor);
 
	bajo=0;
	alto=dimension-1;
	central=(bajo+alto)/2;
 
	/*busqueda binaria*/
	while (bajo<=alto&&arreglo[central]!=valor)
	{
		if (valor<arreglo[central])
		else  bajo=central+1;
		central=(bajo+alto)/2;
		if (valor==arreglo[central]){
			printf("El valor se encuentra en la posicion %i", central);
		} else printf("El elemento no fue encontrado");
		getchar();
 
	}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder