当前位置:网站首页>When the interviewer asks you to write binarysort in two ways
When the interviewer asks you to write binarysort in two ways
2022-06-28 09:08:00 【C_ x_ three hundred and thirty】
package com.Cx_330.Algorithm.BinarySort;
public class BinarySortDemo {
public static void main(String[] args) {
int[] arr=new int[100];
for (int i = 0; i < arr.length; i++) {
arr[i]=i+1;
}
System.out.println(binaryNoRecursion(arr, 67));
System.out.println("********VS*******");
System.out.println(binaryRecursion(arr, 67,0,arr.length-1));
}
public static int binaryRecursion(int[] arr, int key,int left,int right) {
System.out.println("Recursion~~~");
if(left>right||arr[right]<key||arr[left]>key){
return -1;
}
int mid=(left+right)/2;
if(arr[mid]>key){
return binaryRecursion(arr,key,left,mid-1);
}else if(arr[mid]<key){
return binaryRecursion(arr,key,mid+1,right);
}else {
return mid;
}
}
public st边栏推荐
- 理解IO模型
- Stock suspension
- Test cases for learning the basic content of software testing (II)
- Chrome devtools
- Learn how Alibaba manages the data indicator system
- How to solve the problem of high concurrency and seckill
- Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
- Explain observer mode
- Import and export of a single collection in postman
- JMeter -- interface test 1
猜你喜欢

Basic knowledge of hard disk (head, track, sector, cylinder)

Automatic conversion - interview questions

It only takes two steps to find the right PMP organization, one check and two questions

从知识到智慧:知识图谱还要走多远?

Calcul des frais d'achat et de vente d'actions

电子元器件销售ERP管理系统哪个比较好?

Lilda low code data large screen, leveling the threshold of data application development

Expérience d'optimisation SQL: de 30248 secondes à 0001 secondes

Calculation of stock purchase and sale expenses

Import and export of a single collection in postman
随机推荐
Redis5.0 slot migration, free play (single machine migration cluster)
Common test method used by testers --- orthogonal method
Deployment of MySQL database in Linux Environment
状态机程序框架
rman备份报ORA-19809 ORA-19804
DEJA_ Vu3d - 051 of cesium function set - perfect realization of terrain excavation
Using transform:scale causes the page mouse hover event to disappear
基于宽表的数据建模
How to suppress SiC MOSFET crosstalk?
Implementation of single sign on
The Cassandra cluster reinstalls and starts from the node. An error is reported. There is an existing solution
Construire le premier réseau neuronal avec pytorch et optimiser
Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
redis5.0的槽点迁移,随意玩(单机迁移集群)
Music website design based on harmonyos (portal page)
SQL注入之文件读写
华泰证券网上开户安全吗 办理流程是什么
Quickly understand JVM structure and working principle
Screen settings in the source code of OBS Live Room
Fire fighting work and measures in Higher Vocational Colleges