What�s the best way to perform a search on a pdb? I like to use the binary search algorithm but this one looks not so much efficient to solve my problem. I have a list with several products inside that are ordened by their product class. When the user selects choose one class I must show him all products. I tried the sequencial search but it is horrible, now I am triyng the binary but when the code makes its division it may or not get ther first product of my class, than I have to run back to find the first one. It is not good to.
ex.: class product
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
the binary search will divide this list on the 4th item, even I found the right product of my class I must run back to the first product by comparision.
Does anybody have some ideas?
Still use a binary search, just use it to find the first item. Instead of stopping when you find something that matches the class, store that item as the first_found_so_far. Then continue the search as if that record was greater than what you're looking for.
In the continued search look for a record that is less than what you want, but whose index is only 1 less than first_found_so_far. This will be your edge between different classes found in log(n) time.
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
