So I've got the binary search function working for this problem, but I have no idea how to deal with the "found" flag portion of the problem. I think the idea is to add a "true" condition to the bool portion of the typedef struct "words", which is in the struct "dictionary". Just needing a nudge in the right direction. My attempt below is not working.
// Looks up word, s, in dictionary. If found (for the first time), flags word as found (so that user can't score with it again) and returns true
bool lookup(string s) { // TODO int start = 0; int end = dictionary.size;
while (start <= end)
{
int mid = (start + end) / 2;
if (strcmp(s, dictionary.words[mid].letters) == 0)
{
dictionary.words[mid].found = true;
return true;
}
if (strcmp(s, dictionary.words[mid].letters) < 0)
{
end = mid - 1;
}
if (strcmp(s, dictionary.words[mid].letters) > 0)
{
start = mid + 1;
}
}
return false;
}