int binarySearch(const int myArray[], int end, int target, int* locn){ // Binary Search Function // // Inputs: Array to sort, index of last element, // value to search for, pointer to location // to store the index of the value if found // Outputs: Returns 1 if value found, 0 if not // Modifies the value corresponding to the pointer // // local variables int first; int mid; int last; // algorithm first = 0; last = end; while(first <= last){ // calculate mid mid = (first + last)/2; // check value if(target > myArray[mid]) // upper half first = mid + 1; else if(target < myArray[mid]) // lower half last = mid - 1; else // found first = last + 1; } // end while // set value of index // using a pointer to allow multiple returns *locn = mid; // set return to 1 if found, 0 if not found return (target == myArray[mid]); } // end binarySearch