当前位置:网站首页>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 !");
}
}
}边栏推荐
- 国产旗舰手机定价近六千,却连iPhone12都打不过,用户选谁很明确
- Get the current month and year and the previous 11 months
- Take chef and ansible as examples to get started with server configuration
- 3. Realize snake and basic game interface
- Introduction to encryption technology
- Data + AI Summit 2022 PPT 下载
- 有好用的免费的redis客户端工具推荐么?
- Teach you how to use power Bi to realize four kinds of visual charts
- 【论文阅读】TEMPORAL ENSEMBLING FOR SEMI-SUPERVISED LEARNING
- SSM在线租房售房平台多城市版本
猜你喜欢

34. Add two numbers

Data + AI summit 2022 PPT download

3.实现蛇和基本游戏界面

Finclip's "applet export app" function has been updated again by the company

Data + AI Summit 2022 PPT 下载

Voice recognition based on MATLAB

25. Middle order traversal of binary tree

No routines, no traps, no advertisements | are you sure you don't need this free instant messaging software?

Constraintlayout learn from 0 to 0.n

28. Rainwater connection
随机推荐
Get the current month and year and the previous 11 months
26. Reverse linked list II
29. Right view of binary tree
Raspberry pie self built NAS cloud disk -- raspberry pie built network storage disk
Speech processing based on MATLAB
Summary of recent interviews
Implement is by yourself_ default_ constructible
Analysis of ISP one click download principle in stm32
C代码规范
Arduino框架下ESP32 EEPROM库函数实现对各数据类型保存示例
手把手教你用 Power BI 实现 4 种可视化图表
[C language] detailed knowledge of document operation
Relevant laws of animation movement (judge where to move according to parameters)
Proxy
Efficientformer: lightweight vit backbone
猿人学第六题
Redis (13) -- on master-slave replication of redis
Finclip's "applet export app" function has been updated again by the company
[datasheet] interpretation of phy lan8720 network chip
2022.07.21