BINARY SEARCH in VB6

March 5, 2011 at 07:33:54
Specs: Windows 7, B
hey! I'm programming a Binary Search in VB6. Simple enough, however, the data I'm searching has some repetition. For example, SID001, SID001, SID002, SID003 (Representing a Student ID in a transaction file).

The problem I'm having is that I need the program to continue to search when the required record is found, because there could be more. This, again, sounds pretty simple BUT when the code does the usual...
'IF the required record < mid_loc THEN
last_loc = mid_loc
mid_loc = (first_loc + last_loc) /2
...'
It doesn't work BECAUSE the required record is of the same value as the mid_loc.

I hope some of this makes sense to someone, I'd very much appreciate help.

If you need to see the code I've got, I can post that :)

Thanks.


See More: BINARY SEARCH in VB6

Report •


#1
March 5, 2011 at 19:31:39
You have to search two ways. The binary search will find an occurence of the value. You must search backwards to find the first, then forward to find the rest.

Report •

#2
March 6, 2011 at 14:50:27
hey, thanks for the reply :) I see what you're saying. Imma have a crack at it now. really appreciate the help.

Andy


Report •

Related Solutions


Ask Question