Hello,
Does anyone have an algorithm or know a function that can sort a std::string for me?
Say i have:
string one = "test";
sorting it alfabetically would result in > "estt"
Thanks,
Neil.
Printable View
Hello,
Does anyone have an algorithm or know a function that can sort a std::string for me?
Say i have:
string one = "test";
sorting it alfabetically would result in > "estt"
Thanks,
Neil.
Any numerical sort function should work. Each character is just an integer.
Viggy
Do you have some code? I'm lazy ;)
Nope. Sorry, I don't work for free.
Viggy
Check out std::sort in <algorithm>, it was just a google away :)
http://www.cplusplus.com/reference/algorithm/sort/
If you are one of those people that refuses to use the std algorithms for whatever reason there are many examples of sorting functions on the internet that you can find, copy, and paste. there is no reason for anyone else on this forum to post code when you can find examples in about 30 seconds.
What result do you want for the string "cbaCBA"? In other words, are you looking for a case-invariant sort?
Its only caps.
so for example i need to sort the string "TEST" to "ESTT".
Great, then you don't even need to write a custom comparator for std::sort.