Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
STL binary search
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Alex Gerdemann, post: 1513455"] Hello, I am writing a program where I have a vector (std::vector<std:string> list) that I need to search many times. To accomplish this efficiently, I plan to sort the list using std::sort(list.begin(),list.end()), then run binary searches. I need to get the indices of the elements found so I can construct a matrix where I allocate a row of a matrix for each string in the list (row one for the first item in the list, etc). However the binary search algorithm in the STL returns an iterator that points to the object in the vector rather than the index. Is there some way I can use STL to get the index of an element without running a linear search? Thanks, Alex Gerdemann University of Illinois at Urbana-Champaign [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
STL binary search
Top