标签:id3 ati ring magic sea while dom initial div
package demo3;
public class BinarySearch {
public String binarySearch(int[] array,int key)
{
int left = 0;
int right = array.length-1;
while (left<right)
{
int mid = left +(right-left)/2;
if(array[mid]<key)
{
left=mid+1;
}
else if(array[mid]>key)
{
right=right-1;
}
else if(array[mid]==key)
{
return "yes";
}
}
return "no";
}
}
package demo3;
public class TestBinarySearch {
public static void main(String[] args) {
int[] array = {2,1,1,2,3,5,6,7,21,12};
BinarySearch binary = new BinarySearch();
System.out.println( binary.binarySearch(array,4));
}
}
标签:id3 ati ring magic sea while dom initial div
原文地址:https://www.cnblogs.com/zhichun/p/11361265.html