开发者

efficient way of searching a character in a set of character C language

开发者 https://www.devze.com 2022-12-31 15:03 出处:网络
I have a set of characters, minimum hundreds of characters. How could i get the position 开发者_如何学编程of aparticular character in that list efficiently.If you set of characters is sorted, you can

I have a set of characters, minimum hundreds of characters. How could i get the position 开发者_如何学编程of a particular character in that list efficiently.


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().


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

0

精彩评论

暂无评论...
验证码 换一张
取 消