当前位置:网站首页>当面试官让你用两种方式写BinarySort
当面试官让你用两种方式写BinarySort
2022-06-28 09:06:00 【C_x_330】
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
边栏推荐
猜你喜欢
[untitled]
用Pytorch搭建第一个神经网络且进行优化
电子元器件销售ERP管理系统哪个比较好?
The Cassandra cluster reinstalls and starts from the node. An error is reported. There is an existing solution
Installation of containerd1.5.5
MATLAB小技巧(20)矩阵分析--主成分回归
SQL 优化经历:从 30248秒到 0.001秒的经历
Loggerfactory uses log4j Parameter introduction of properties
RMAN backup message ora-19809 ora-19804
硬盘基本知识(磁头、磁道、扇区、柱面)
随机推荐
Fire fighting work and measures in Higher Vocational Colleges
Is it safe to open an account for mobile phone stock speculation?
Tree
RMAN backup message ora-19809 ora-19804
break database---mysql
Apache Doris becomes the top project of Apache
Use of Jasper soft studio report tool and solution of thorny problems
Fire safety hazards
Is it safe for CICC fortune to open an account? How much do you charge?
Ffmpeg streaming fails to update header with correct duration
Guangzhou: new financial activities and new opportunities for enterprises
个人究竟如何开户炒股?在线开户安全么?
containerd1.5.5的安装
Decision table method for basic content learning of software testing (2)
【无标题】
Quickly understand JVM structure and working principle
[.Net6] GRP server and client development cases, as well as the access efficiency duel between the minimum API service, GRP service and traditional webapi service
Almost union find (weighted union search)
rman備份報ORA-19809 ORA-19804
Stock suspension