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

while(low <= high)/2;

This line has multiple errors. Redo it and recompile.

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.

• 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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.