how to do a binary search without using an array in java
<p>I'm trying to create a binary search that doesn't use an array. It also needs to count how many searches it does until it finds the number. I also have to use a randomaccessfile.</p>

<pre><code>RandomAccessFile raf=new RandomAccessFile(new File("Project 10"),"rw");

//writing in random numbers. Different numbers will be used when it is being tested

raf.writeInt(-5);
raf.writeInt(-1);
raf.writeInt(122);
raf.writeInt(124);
raf.writeInt(125);
raf.writeInt(256);
</code></pre>

<p>user input what number do you want to search for. I need to do this without using the scanner class. the method to do this will be very helpful</p>

<p>I know this is how you do a binary search with an array. I need help figuring out how to do it without an array</p>

<pre><code>public static int binarySearch(int[] list, int key) {
    int low = 0;
    int high = list.length - 1;

    while (high &gt;= low) {
        int mid = (low + high) / 2;
        if (key &lt; list[mid])
            high = mid - 1;
        else if (key == list[mid])
            return mid;
        else
            low = mid + 1;
    }
    return -low - 1; // Now high&lt;low, key not found
}
</code></pre>
