Page 1 of 1

Bsearch---built in

Posted: Fri Dec 12, 2003 3:09 pm
by nikhil
Can anyone pls tell me how to handle "struct" with the help of
built in "bsearch". :lol: i tried with normal tcwin(not vc) help
but failed to handle the search of "string"
pls tell me what can i do 4 searching strings
or even is there any other option which is more efficient :P
thx in advance.

Re: Bsearch---built in

Posted: Tue Oct 07, 2008 5:32 pm
by lnr
To nikhil

Code: Select all

binary_search() from STL.

Re: Bsearch---built in

Posted: Tue Oct 07, 2008 6:03 pm
by mf
Hmm, I doubt that the example in your code would work - the array has to be sorted for binary search.

Re: Bsearch---built in

Posted: Wed Oct 08, 2008 5:45 am
by lnr
I am very sorry.
Yes you are absolutely right.

Re: Bsearch---built in

Posted: Thu Dec 09, 2010 10:36 pm
by gtcoder
If you're talking about bsearching on an array of structs then you need to have your query in the same kind of struct. Then just customize the compare function for strcmp(), if that's what u r asking.