There is 16 question about this simple class , but I\"m not understanding it The
ID: 3654810 • Letter: T
Question
There is 16 question about this simple class , but I"m not understanding it
The question at the comments ,, like // 1- why ? // 2- what ,,, it's 16 questions
Please answer them carefully :)
The class is here :http://wikisend.com/download/936170/OrdArray.java
Or you can find it here :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ds_lab_2;
/**
*
* @author
*/
public class OrdArray {
private long[] a; // ref to array a
private int nElems; // number of data items
/////////////////////////////////////////////////////
public OrdArray(int max) // constructor
{
a = new long[max]; // create array
nElems = 0;
}
/////////////////////////////////////////////////////
public int size()
{ return nElems; }
/////////////////////////////////////////////////////
public int find(long searchKey) // 1- I just noticed that this is binary search , what is it and how it works ?
{
int lowerBound = 0; // 2- For what this ?
int upperBound = nElems-1; // 3- For what this , and why nElems-1 , why not +1 ?
int curIn;
while(true)
{
curIn = (lowerBound + upperBound ) / 2; // 4- Why this sentence ?
if(a[curIn]==searchKey) // 5- what does it do ?
return curIn; // found it
else if(lowerBound > upperBound) // 6- why lower > upper ?
return nElems; // can