我有这个,但是方法没有显示在bluej中创建的对象上。
如何在int数组上进行二进制搜索然后输出找到的int?

public static int binarySearch(int a[], int element)
{
    int first = 0;
    int upto = a.length;

    while (first < upto)
    {
        int mid = (first + upto) / 2;  // Compute mid point.
        if (element < a[mid])
        {
            upto = mid;                // repeat search in bottom half.
        } else if (element > a[mid])
            {
                first = mid + 1;       // Repeat search in top half.
            }
                else
                {
                    return mid;        // Found it. return position
                }
            }
     return -(first + 1);              // Failed to find key
  }

最佳答案

您将方法设为静态。因此,它很可能出现在类的上下文菜单中而不是对象。

关于java - 如何在bluej中的Java中实现二进制搜索?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8343170/

10-11 22:34
查看更多