=1&&a[j-1]>t;j——)[j]=[j-1];[j]=t;}}空display(){System.out.println("给定的列表是");为(int我=0;我 =1&&a[j-1]>t;j——)[j]=[j-1];[j]=t;}}空display(){System.out.println("给定的列表是");为(int我=0;我
登录
首页 » 算法 » 二进制搜索 java 代码

二进制搜索 java 代码

于 2023-01-30 发布 文件大小:4.29 kB
0 161
下载积分: 2 下载次数: 1

代码说明:

导入 java.util.* ;类 BinarySearch{int [] ;无效的 get){扫描仪 sc = 新的 Scanner(System.in) ;System.out.println ("输入 no。元素") ;= 新 int[sc.nextInt()] ;System.out.println ("输入元素") ;为 (int 我 = 0 ; 我 < a.length;i++)a[i]=sc.nextInt() ;}int binarySearch (int n){int 低 = 0 ;int high=a.length-1 ;虽然 (低 < = 高){int 中期 =(low+high)/2 ;if(a[mid]==n)返回 (中期) ;if(n = 1 & & a [j-1] > t; j — —)[j] = [j-1] ;[j] = t ;}}空 display(){System.out.println ("给定的列表是") ;为 (int 我 = 0 ; 我 < a.length;i++)System.out.print ([i] +"") ;System.out.println() ;

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • 平均因子分解应用于正定矩阵
    平均因子分解法,适用于正定矩阵First, let s recall the definition of the Cholesky decomposition: Given a symmetric positive definite square matrix X, the Cholesky decomposition of X is the factorization X=U U, where U is the square root matrix of X, and satisfies: (1) U U = X (2) U is upper triangular (that is, it has all zeros below the diagonal). It seems that the assumption of positive definiteness is necessary. Actually, it is "positive definite" which guarantees the existence of such kind of decomposition. -Average factor decomposition method applied to positive definite matrix First, let s recall the definition of the Cholesky decomposition: Given a symmetric positive definite square matrix X, the Cholesky decomposition of X is the factorization X = UU, where U is the square root matrix of X, and satisfies: (1) UU = X (2) U is upper triangular (that is, it has all zeros below the diagonal). It seems that the assumption of positive definiteness is necessary. Actually, it is positive
    2022-10-16 04:30:02下载
    积分:1
  • Two strings to find the longest common sub
    找出两个字符串的最长公共子串。 给出一个字符串,请删除该字符串的前导空格和尾随空格,中间的空格若多余1个删减到1个。 我是个菜鸟,但软件会是我终生的事业~我有信心学好它,希望站长通融-Two strings to find the longest common sub-string. Given a string, remove the string leading spaces and trailing spaces, if the extra spaces in the middle of a cut to one. I was a rookie, but the software will be my lifelong career ~ and I am confident to learn it, and hope that owners accommodation
    2023-05-01 09:20:03下载
    积分:1
  • 一个以状态方表示的非线性系统,用其仿真模型,NLJ优化
    一个以状态方法表示的非线性系统,用其仿真模型,NLJ优化算法-State that a method of nonlinear systems, using the simulation model, NLJ optimization algorithm
    2022-06-26 22:16:57下载
    积分:1
  • 测试用9721
    测试用9721
    2023-08-15 11:10:02下载
    积分:1
  • 二维有限微分导热模型
    二 维热传导模型的有限元分析。可以改变热导率的参数,仿真时间,平面,输出的数据包括时间为三维!——Dimensional finite element analysis of heat conduction model. Can change the parameters of the conductivity, the simulation time, flat, the output of three-dimensional data, including time!
    2022-03-03 04:42:35下载
    积分:1
  • 快速表达式运
    快速表达式运算 - The fast expression operates
    2022-10-06 00:55:03下载
    积分:1
  • Pi BBP
    本程序实现了BBP算法生成一些十六进制数字后立即开始,一个给定的位置ID,或者换句话说 请点击左侧文件开始预览 !预览只提供20%的代码片段,完整代码需下载后查看 加载中 侵权举报
    2022-03-11 11:50:32下载
    积分:1
  • 光子晶体能带的程序,用matlab编写,比较容易理解!
    计算光子晶体能带的程序,用matlab编写,比较容易理解!-photonic crystals can be calculated with the procedures used Matlab to prepare, easier to understand!
    2022-01-23 10:31:53下载
    积分:1
  • 使用 heristic,BFS,DFS,N 谜题 * 和 c# 的曼哈顿
    问题 (或游戏) n 谜题是可能非常熟悉我们作为初学者有访问在人工智能领域的课程。它是闻名其许多的版本和不同的名称,如 8 拼图,15 拼图,宝石拼图,老板的谜题,十五岁,神秘主义者广场的游戏......在最简单的水平,我想说关于 8 拼图。②。A * 搜索算法A * 搜索算法是相关图,并找出方法中常用的问题。这是也选择不只是因为其效力,因为它容易理解和安装。您需要在继续之前了解该算法。那麼,我奖励已经知道关于这一理论,但为方便参考,您可以阅读下面的两个链接:-A * 搜索算法-A * 搜索算法三。问题分析— — 正如在上一篇文章中讨论,有表的状态不会转给目标状态,我们称之为配置有效和无效。他们之间的比率是 ½,这可以很容易认出从查看会计方法可以提供国家目的或不。-它的容易看到每个表的状态是 mxm 置换 (其中 m 是边缘) 的元素,因此其状态空间 (mxm) !与 8-谜题是 9 != 362 880 (m = 3) 和第 15-拼图是 16 岁 != 20922789888000 (m = 4)。你不如 m 增加 1 个单位,状态空间增加的非常迅速,这使得 m > 3 很少适用的决议版本。-适用 A * 算法解决这个问题,你需要一个启发式函数 h 来估计每个状态 "s 车牌的价值。有几种方法你可以知道距离作为计算基于方差的细胞数与正确的位置,或简单地数出多少个单元格在错误的位置,......在这里,我选择第一种方法,即平方偏差相比其正确位置的单元格数目。这种计算常用,它被称为曼哈顿。
    2022-05-26 02:07:25下载
    积分:1
  • 程序化交易--暴风雨源代码
    应用背景主要运用在外汇交易上,主要使用MT4平台上的各个商品和货币交易                                                                                                        关键技术每个人的看法不一样,结果只有使用者自己去决定,不过这个程序运转需要不少的钱,一般需要2万美金以上才比较安全可以使用。所以对外盘感兴趣的朋友,需要自己多测试后才运用,并且使用自己熟悉的参数来使用。
    2022-12-26 09:45:03下载
    积分:1
  • 696516资源总数
  • 106918会员总数
  • 4今日下载