Good Afternoon,
How would you solve a question that states: assume an array of structure is in order by studentID field of the record, where student IDs go from 101 to 500. Write the pseudocode to find the record with a specific studentID if every single student ID from 101 to 500 is used and the array has 400 elements.
So far I have this:
int binarySearch(int a[], int key)
{
int low = 0;
int high = a.length -1;
int middle;
while(low <= high)/2;
if(key == a[middle])
return middle;
else if (key < a[middle])
high = middle -1;
else
low = middle + 1;
}
return -1;
}
But is code doesn't work because it find a record with a studentID near the end.
Any help that I can get is really appreciated and any suggestions are welcome
Thanks