I have some data stored in vector ;
vector<string> data ;
I want to sort strings in data, alphabetically.Are there any sorting algorithm or complex library which you can recommend me?
Ex ;
assume in data ;
aaaa
ccc
bbb
acb
after sorting, data ;
aaaa
acb
bbb
ccc
4 Answers 4
The Standard library's <algorithm>
header has a sort
function you can use, see: http://www.cplusplus.com/reference/algorithm/sort/
Comments
Since you are aiming for efficiency even before starting to write a program, do it other way around : first write a correct program, then profile it and optimize bottlenecks.
Therefore, I can only recommend what other already did : std::sort
Comments
Normal std::sort
should do the job for you, see this snippet on ideone.
Comments
You can use trie trees http://en.wikipedia.org/wiki/Trie
Vector
? Did you write it yourself? Did you meanvector
(lowercase) from the STL? It's hard to know how to help you without more details about this type.std::sort
and forget about the issue until you recognize it as a problem? Note that your set of requirements might be ill-defined, if you demonstrate that you do need something faster thanstd::sort
, then you most probably don't want to use astd::vector
(BTW, if you prepend standard types withstd::
in questions, it will be clear that you refer tostd::vector
and nothomebrew::vector
)