当前位置:网站首页>二分法
二分法
2022-08-09 15:36:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
package 算法;
import java.util.Arrays;
public class 二分法 {
public static void main(String[] args) { // TODO Auto-generated method stub int[] arr={12,3,34,5,34,5,5,6,2,9,3}; int bar=34;//要找的元素 Arrays.sort(arr); int min=0; int max=arr.length-1; boolean ison=true; System.out.println(“e”); while(ison){ if(arr[(min+max)/2]==bar){ ison=false; System.out.println(“找到了”); break; } if(arr[(min+max)/2]>bar){ max=(min+max)/2-1; } if(arr[(min+max)/2]<bar){ min=(min+max)/2+1; } if(max-min<=0){ ison=false; System.out.println(“没找到”); } } if(ison)System.out.println(“没找到”); }
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/106027.html原文链接:https://javaforall.cn
边栏推荐
- 开始记录自己的学习过程和目标
- C语言三大循环while,for,do...while
- 开源星「001 号」落地 FlyFish,欢迎登陆赢神秘大礼包!
- AVL树的插入操作
- 知识点滴 - 如何写项目总结
- Heap series_0x09: Example of heap corruption (illegal access + uninitialized + heap handle mismatch)
- 网络——IPV4地址(一)
- Became CTO, was killed by my boss in 6 months, I lost 10 million
- 2022-08-09日报:做学术OR去公司 ? 想通这点,治好 AI 打工人的精神内耗
- 初识C语言,了解一下C语言轮廓
猜你喜欢
随机推荐
【挨踢(IT)初体验】
如何判断闰年
1. Introducing GEE and Geemap
The first day of the real in CSDN
No need to pay for the 688 Apple developer account, xcode13 packaged and exported ipa, and provided others for internal testing
无需支付688苹果开发者账号,xcode13打包导出ipa,提供他人进行内测
网络——TCP拥塞控制
五.初始指针
苹果开发者账号 申请 D-U-N-S 编号
Why does a four-byte float represent a wider range than an eight-byte long
The second chapter: create an interactive map (2.1 2.3)
一个程序员的水平能差到什么程度?
Chapter 3: Use of GEE Data (3.1-3.3)
Chapter 3: Use of GEE Data (3.4-3.11)
ESP8266-Arduino编程实例-MQ-6异丁烷丙烷传感器驱动
5G NR Paging 寻呼
四.数组传参
求素数的三种方法
C语言基本数据类型的存储大小、取值范围、输出格式的解剖
【Chinese and English Catalog】Introduction








