A
Alex Gerdemann
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
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