tags:

views:

62

answers:

2

Hi,

I have a set of characters, minimum hundreds of characters. How could i get the position of a particular character in that list efficiently.

+2  A: 

If you set of characters is sorted, you can use bsearch().

If not, you're pretty much out of luck - you'll have to use a simple scan, like strchr().

caf
A: 

convert the set into a ordered list and use binary search.

sza
@SiegFried Ok. even then converting into a list will consume time. Will the time in converting to list will be effective w.r.t speed effectively.
iSight
If there will be multiple search operations based on the set. So it is always no worse than the simple scan.
sza
@SeigFried Thanx for the suggestion...
iSight