0

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

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by NathanOliver
0

Write the pseudocode to find the record with a specific studentID

Well, do what the instructions say. If you have a list of numbers, how would you find a specific number?

Assume each number is on 1 index card in a file box. Write down each step (the psuedocode) you use to find the proper card. When your steps work, you have psuedocode that should be easily translatable into C++ Code.

0

• If all of the elements are in order and the entire array is full wouldn’t you just look at the index of id number - 101?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.