Java¶þ·Ö·¨
Ìù¶Î´úÂë,ÓÐÉÙÐí×¢ÊÍ:
package ibees;
import java.util.Arrays;
public class BinarySearch {
/**
* @param args
*/
public static void main(String[] args) {
double[] src = new double[]{1.3,9.9,10.89,12.89,89.0};
System.out.println(new BinarySearch().binarySearch(src, 89.0));
}
/**
* ¶þ·Ö·¨²éÕÒ
* */
public int binarySearch(double[] src, double des){
Arrays.sort(src);
int beginIndex = 0;
int endIndex = src.length-1;
int middle = (endIndex+beginIndex)/2;
while(src[middle] != des && beginIndex != endIndex){
//×îºóÁ½Ïî
if(beginIndex+1 == endIndex){
if(src[beginIndex] == des){
return beginIndex;
}else if(src[endIndex] == des){
return endIndex;
}else{
return -1;
}
}
//ÅжÏÖмäµÄÊýÓë¸ø¶¨ÊýÖ®¼äµÄ¹Øϵ
if(des > src[middle]){
beginIndex = middle+1;
}else if(des < src[middle]){
endIndex = middle-1;
}else{
return middle;
}
middle = (endIndex + beginIndex)/2;
}
return middle;
}
}
ÏëÏë·µ»ØµÄÊý×éË÷ÒýÊDz»¶ÔµÄ¡£
Ïà¹ØÎĵµ£º
£¨1£©Ìí¼Ó±àÒëjava²Ëµ¥
1¡¢´ò¿ª ¸ß¼¶£>¹¤¾ßÅäÖÃ
2¡¢ÔÚ“ÃüÁîÀ¸”ÀïÊäÈë javac %n%e £¨%nΪÎļþÃû²»´øÀ©Õ¹Ãû£¬%eΪÀ©Õ¹Ãû£©
3¡¢ÔÚ“¹¤×÷Ŀ¼”ÉÏÌî %p (±íʾÎļþËùÔÚĿ¼)
4¡¢ÔÚ“²Ëµ¥ÏîÄ¿Ãû³Æ”ÉÏÊäÈë ±àÒëjava³ÌÐò £¨ÏÖÔÚÔڲ˵¥ÉϵÄÃû³Æ£©
5¡¢Ñ¡Ôñ“±£´æµ±Ç°Îļþ”¸´Ñ¡¿ ......
ÔÌâÈçÏ£ºÓÃ1¡¢2¡¢2¡¢3¡¢4¡¢5ÕâÁù¸öÊý×Ö£¬ÓÃjavaдһ¸ö³ÌÐò£¬´òÓ¡³öËùÓв»Í¬µÄÅÅÁУ¬È磺512234¡¢412345µÈ£¬ÒªÇó£º"4"²»ÄÜÔÚµÚÈý룬"3"Óë"5"²»ÄÜÏàÁ¬¡£
½âÌâ˼·£º
ºÜÃ÷ÏÔ£¬ÕâÊÇÒ»¸öµÝ¹éËã·¨¡£ÎÒÃÇ¿ÉÒÔÅÅÁн«Õâ6¸öÊý°´´ÓСµ½´óµÄ˳ÐòÅÅһϣ¬Èç¹ûÊÇ1,2,3,4,5,6£¬ÄÇô»áÓÐ1 ......
SQL×¢ÈëÊÇ×î³£¼ûµÄ¹¥»÷·½Ê½Ö®Ò»,Ëü²»ÊÇÀûÓòÙ×÷ϵͳ»òÆäËüϵͳµÄ©¶´À´ÊµÏÖ¹¥»÷µÄ,¶øÊdzÌÐòÔ±ÒòΪûÓÐ×öºÃÅжÏ,±»²»·¨
Óû§×êÁËSQLµÄ¿Õ×Ó,ÏÂÃæÎÒÃÇÏÈÀ´¿´ÏÂʲôÊÇSQL×¢Èë:
±ÈÈçÔÚÒ»¸öµÇ½½çÃæ,ÒªÇóÓû§ÊäÈëÓû§ÃûºÍÃÜÂë:
& ......
¶àÏ̶߳Áдͬһ¸ö¶ÔÏóµÄÊý¾ÝÊǺÜÆÕ±éµÄ£¬Í¨³££¬Òª±ÜÃâ¶Áд³åÍ»£¬±ØÐë±£Ö¤ÈκÎʱºò½öÓÐÒ»¸öÏß³ÌÔÚдÈ룬ÓÐÏß³ÌÕýÔÚ¶ÁÈ¡µÄʱºò£¬Ð´Èë²Ù×÷¾Í±ØÐëµÈ´ý¡£¼òµ¥Ëµ£¬¾ÍÊÇÒª±ÜÃâ“д-д”³åÍ»ºÍ“¶Á-д”³åÍ»¡£µ«ÊÇͬʱ¶ÁÊÇÔÊÐíµÄ£¬ÒòΪ“¶Á-¶Á”²»³åÍ»£¬¶øÇҺܰ²È«¡£
ҪʵÏÖÒÔÉϵÄReadWriteLock£¬ ......