Bsearch---built in

Write here if you have problems with your C source code

Moderator: Board moderators

Post Reply
nikhil
New poster
Posts: 11
Joined: Wed Oct 08, 2003 1:37 pm

Bsearch---built in

Post 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.
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: Bsearch---built in

Post by lnr »

To nikhil

Code: Select all

binary_search() from STL.
Last edited by lnr on Fri Oct 17, 2008 9:01 pm, edited 5 times in total.
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Re: Bsearch---built in

Post by mf »

Hmm, I doubt that the example in your code would work - the array has to be sorted for binary search.
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: Bsearch---built in

Post by lnr »

I am very sorry.
Yes you are absolutely right.
gtcoder
New poster
Posts: 12
Joined: Tue Mar 23, 2010 5:45 am

Re: Bsearch---built in

Post 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.
Post Reply

Return to “C”