Help with flowchart using binary search

int binSearch (int[] ptNos, int ptNum) { 

// A method called binSearch will return an int and requires an array of ints and an int to search for
// This version of the binary search approach will only work if the array contains ints in order from
// largest to smallest or smallest to largest

// 1. INITIALIZE VARIABLES

int ptCount = ptNos.length; // This is missing from the flow chart but was referenced by var "last"
int first = 0; // This will be used as the index of the first element in a range within your array "ptNos"
int last = ptCount - 1; // This will be used as the index of the last elment in a a range with your array
int found = 0; // It's 0 by default but changes to 1 if your number is found
int target = ptNum; // Your flow chart calls the parameter "ptNum" but refers to it in the chart as "target"
int mid = 0; // And you need a midpoint 

// By jumping ahead by half each time through the loop and comparing variables
// before or after the midpoint as being too big or too small to consider later.
// LATER. THE RESULT IS THAT YOU MAKE A DIRECT COMPARISON AS FEW TIMES AS
// POSSIBLE (I.E. EFFICIENCY)

// 2. EVERYTHING GOES IN A LOOP THAT WILL COMPARE VALUES IN THE ARRAY TO "ptNUM"
for (int i = 0; i < ptCount; i++) {

    // 3. Only search if there is anything left in the search range (btw first and last) AND 
    //    if you haven't found anything yet
    if (first <= last && found == 0 ) {

        // 4. Update the midpoint 
        mid = (first + last) / 2;

        // 5. Check if the item in the array at your midpoint is equal to your target/ptNum value
        if (ptNos[mid] == target) {
            found = 1; // If it is, change found from 0 (false) to 1 (true) 
        }
        // 6. If it's not equal, check if it's less. Then change either first or last in your range accordingly
        if (ptNos[mid] < target) {
            first = mid + 1;
        } else {
            last = mid - 1;
        }
    } else {
        // 7. Once you've checked the whole array, your range btw first and last will be 0.
        // And if the range is 0 and you still haven't found your target (hence found ==0) then return -1
        // But if you did find it, mid will be the location of the index of the think you were looking for
        if (found == 0) {
            mid = -1;
        }
        return mid;
    }
  }
}
/r/javahelp Thread