Originally Posted by
panosstylianou
well tater is quite right about my level. i'm quite a beginner. But thanks everyone about your suggestions. i guess i'll have to work my ass off and understand these things, that look really simple to you
i might have to do just the spell checking without the suggestion part cause i guess a week is not enough. But still i'll check it out and see if its anywhere near possible within a week.
A spell checker *without* suggestions? As Hollywood would say: "That's unacceptable soldier!"
It's simple to do. Here's a basic binary search function, for words:
Code:
int binarySearch(const char goal[], int left, int right) {
int lo, mid, hi,count=0;
lo=left;
hi=right;
while (lo <= hi) {
++count;
mid = (lo + hi) / 2;
/* watch how the binary search zerooes in on the goal word */
//printf("goal: %s mid: %d words[mid]: %s ", goal, mid, words[mid]);
//printf("stringcmp returns: %d\n", strcmp(goal, words[mid]));
//getchar();
if (strcmp(goal, words[mid]) < 0) //goal < words[mid]: -1
hi = mid-1;
else if(strcmp(goal, words[mid]) > 0) //goal > words[mid]: 1
lo = mid+1;
else
return mid;
}
return -1;
}
If the word is found, obviously no suggestions are wanted, so it's the very last part of the function that needs just a tweak to give you the suggestions:
Code:
}
(in pseudo code)
print Nearest words found are:
=======================
print words[mid-2]
print words[mid-1]
print words[mid]
print words[mid+1]
print words[mid+2]
return -1;
}
All based on mid being the closest value to the word being searched for. If +2 and -2 aren't large enough, try +5 -5.
"And you WILL adapt and overcome, Marine!