2019.12.07 二分法查找二维数组

/**
* BinarySearch.java
* com.oracle.array
*
* Function: TODO
*
* ver date author
* ──────────────────────────────────
* 2019年12月5日 17671
*
* Copyright (c) 2019, TNT All Rights Reserved.
*/

package com.oracle.array;
/**
* ClassName:BinarySearch
* Function: TODO ADD FUNCTION
* Reason: TODO ADD REASON
*
* @author 17671
* @version
* @since Ver 1.1
* @Date 2019年12月5日 下午8:51:26
*
* @see
*/
public class BinarySearch {
public static String[][] news= {{"京东物流","100"},{"家乐福","400"},
{"百度搜索","600"},{"4399小游戏","1000"}};
public static void main(String[] args) {
binarySearch(600);
}
public static void binarySearch(int value) {
int start=0;
int end=news.length-1;
while(start<=end) {
int mid=(start+end)/2;
if (value==Integer.parseInt(news[mid][1])) {
System.out.println("点击数为"+value+"对应的名称为:"+news[mid][0]);
break;
}else if(value>Integer.parseInt(news[mid][1])){
start=mid+1;
System.out.println("向右折半");
}else if(value<Integer.parseInt(news[mid][1])) {
end=mid-1;
System.out.println("向左折半");
}

}
}
}

猜你喜欢

转载自www.cnblogs.com/aojie/p/12000582.html