C++ what is position doing in this binary search function?
int binarySearch(int array[], int size, int value) //value is the number you want to look for { int first = 0, // First array element last = size - 1, // Last array element middle, // Mid point of search position = -1; // Position of search value bool found = false; // Flag int numOfRounds = 0; while (!found && first <= last) { middle = (first + last) / 2; // Calculate mid point if (array[middle] == value) // If value is found at mid { found = true; position = middle; cout << "value is found at mid" << endl; cout << "it is found!" << endl; } else if (array[middle] > value) // If value is in lower half { last = middle - 1; cout << "value is found at lower half" << endl; numOfRounds++; } else { first = middle + 1; // If value is in upper half cout << "value is found at upper half" << endl; numOfRounds++; } if (!(array[middle] == value)) { cout << "value is NOT found" << endl; } cout << "Number of rounds: " << numOfRounds << endl; cout << "- - - - - - - - - - - - - - - - -" << endl; } return position; }