当前位置:网站首页>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边栏推荐
- Chrome devtools
- Discussion on the improvement and application of the prepayment system in the management of electricity charge and price
- Boundary value analysis method for learning basic content of software testing (2)
- How to solve the problem of port number occupation
- Calcul des frais d'achat et de vente d'actions
- Container adapter - stack: stack queue: queue priority_ Queue: priority queue
- 图解MySQL的binlog、redo log和undo log
- 如何实现基于 RADIUS 协议的双因子认证 MFA?
- new URL(“www.jjj.com“)
- Mysql8.0 forgot the root password
猜你喜欢
随机推荐
Application of current limiting protector in preventing electrical fire in shopping malls
RMAN backup message ora-19809 ora-19804
在本类私有属性直接使用?new()在使用!!!
[big case] Xuecheng online website
【大案例】学成在线网站
A - Bi-shoe and Phi-shoe
Stock suspension
State machine program framework
1182:合影效果
rman備份報ORA-19809 ORA-19804
Power data
1. Kimball dimension modeling of data warehouse: what is a fact table?
How to solve the problem of port number occupation
It only takes two steps to find the right PMP organization, one check and two questions
Implementation of code scanning login
Trailing Zeroes (II)
SQL optimization experience: from 30248 seconds to 0.001 seconds
华泰证券网上开户安全吗 办理流程是什么
Copy & Deepcopy
Fire fighting work and measures in Higher Vocational Colleges








