April 2021 2 449 Report

¿busqueda binaria con string en java?

necisito el cogido para buscar mediante el metodo binario en un vector de string

t={"casa",......."amarillo"}

tengo el codigo pero solo funciona con enteros ordenados

public static int Binariabuscar( int [] arreglo, int dato) {//arreglo seria de estring y el dato string

int inicio = 0;

int fin = arreglo.length - 1;

int pos;

while (inicio <= fin) {

pos = (inicio+fin) / 2;

if ( arreglo[pos] == dato )

return pos;

else if ( arreglo[pos] < dato ) {// esta sentencia no se puede con string

inicio = pos+1;

} else {

fin = pos-1;

}

}

return -1;

}

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 ANSWERS.MX - All rights reserved.