這篇文章給大家分享的是有關(guān)java數(shù)據(jù)結(jié)構(gòu)之二分查找法binarySearch的示例分析的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。
java數(shù)據(jù)結(jié)構(gòu)之二分查找法 binarySearch的實(shí)例
折半查找法,前提是已經(jīng)排好序的數(shù)組才可查找
實(shí)例代碼:
public class BinarySearch { int[] bArr; public void setArr(int[] bArr){ this.bArr=bArr; } public static void main(String[] args) { int arrLength=16; int[] bArr=new int[arrLength]; System.out.println("數(shù)組:"); bArr=new int[]{72,31,13,94,85,27,64,71,19,55,49,40,8,70,17,13}; for(int i=0;ibArr[mid]){ return binarySearch(max,mid,val); } else if(val 感謝各位的閱讀!關(guān)于“java數(shù)據(jù)結(jié)構(gòu)之二分查找法binarySearch的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
標(biāo)題名稱:java數(shù)據(jù)結(jié)構(gòu)之二分查找法binarySearch的示例分析-創(chuàng)新互聯(lián)
文章起源:http://www.weahome.cn/article/djdpsd.html