当前位置:网站首页>binary search
binary search
2022-07-24 13:08:00 【Cording..】
public class ArrayTest2 {
public static void main(String[] args) {
boolean isFlag = true;
// Binary search :( be familiar with )
// Premise : The array to be found must be ordered .
int[] arr2 = new int[]{-98,-34,2,34,54,66,79,105,210,333};
int dest1 = -34;
dest1 = 35;
int head = 0;// Initial first index
int end = arr2.length - 1;// Initial last index
boolean isFlag1 = true;
while(head <= end){
int middle = (head + end)/2;
if(dest1 == arr2[middle]){
System.out.println(" The specified element was found , The position is :" + middle);
isFlag1 = false;
break;
}else if(arr2[middle] > dest1){
end = middle - 1;
}else{//arr2[middle] < dest1
head = middle + 1;
}
}
if(isFlag1){
System.out.println(" unfortunately , Not found !");
}
}
}边栏推荐
猜你喜欢

Digital intelligence integration accelerates enterprise business innovation

Handler learning

Wang Ping, co-founder of Denglin Technology: Innovation + self research "dual core" drive, gpu+ enabling AI takes root | quantum bit · viewpoint sharing review

setAttribute、getAttribute、removeAttribute

2022.07.21

It is difficult for Chinese consumers and industrial chains to leave apple, and iPhone has too much influence

About thread (4) thread interaction

26. Reverse linked list II

The second batch of projects of Shenzhen Metro Line 12 passed the acceptance and is expected to be put into trial operation on July 28

2022.07.21
随机推荐
Roller_ Block default behavior_ Zero roll event compatible
23. Spiral matrix
setAttribute、getAttribute、removeAttribute
IUAP spring training data in 2022, Zhongtai training report
Modern data architecture selection: Data fabric, data mesh
The EAS BOS development environment client cannot be started, but the server does show that it is ready
【论文阅读】Mean teachers are better role models
手把手教你用 Power BI 实现 4 种可视化图表
Analysis of ISP one click download principle in stm32
Redis(13)----浅谈Redis的主从复制
Getting started with SQL join use examples to learn left connection, inner connection and self connection
Step of product switching to domestic chips, stm32f4 switching to gd32
Digital intelligence integration accelerates enterprise business innovation
Constraintlayout learn from 0 to 0.n
The MySQL select delay scenario corresponds to that all database query statements will be delayed. After the scenario injection, I executed one
[stm32] internal independent watchdog iwdg
Video realizes the control of video progress, playback and pause
SSM hospital inpatient management system
Modification of EAS login interface
Summary of recent interviews