for each (String^ name in toBeFound)
{
int result = 0;
result = Array::BinarySearch(names, name);
if (result > 0)
Console::WriteLine("{0}, {1}", name, weights[result]);
else
Console::WriteLine("{0} is not found", name);
}
Microsoft C++ makes me want to cry. They butcher standard C++ into something nobody can comprehend.
A Binary search relies on your array being sorted in alphabetical order. Your names are sorted based on weight? If so, "Al" should have the lowest weight. Not "Zoe".
Actually, the names and weights are pairs one by one, like (Jill, 103).
when you use Array::Sort(), it will just sort the names array in alphabetical order and the element of weight array will match the order of the names array.
The problem is I can binarysearch any name including "Zoe" but "Al". I am just wondering is anything wrong with the Array::BinarySearch().