好的,在给定一个有序数组的情况下,使用二进制搜索的方法查找作为参数传递的特定元素的索引。如果在数组中没有找到搜索到的数字,则返回-1。示例: array = [1,2,3,4,5,6,7,8,9,10];[Where2 would be the number on which we want to know its position in
对于java数组上的经典binarySearch (例如String[] a),调用搜索方法的正确方法是什么?是吗或我尝试了以下两种实现,而且这两种方法似乎都有效。这些调用中的任何一个都可能失败吗?class BS{
public static int binarySearch(String[] a,String
输出对比二进制搜索树的java时出现错误: 现在我要搜索数组中的一些值,我需要创建一个方法来处理它吗?例如,我要找出22个比较。我如何实现这一点?这里的答案是: public static void main(String [] args) { int i = binarySearch(0, new int[]{9, 21, 33, 44, 66, 72,
基本上,im应该添加一个名为binarySearch的新的私有通用方法。
该方法应该实现递归二进制搜索算法,并查找与在searchLastName方法参数中传递的值相同的姓氏字段的元素。然而,我认为我是正确的,但我在两个.get (错误:找不到符号)上都有一个错误。private static < E extends People > int binarySearch(ArrayList<E>