-
March 22nd, 2010, 12:10 PM
#1
String sort in Alphabetical order
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.
-
March 22nd, 2010, 12:11 PM
#2
Re: String sort in Alphabetical order
Any numerical sort function should work. Each character is just an integer.
Viggy
-
March 22nd, 2010, 12:12 PM
#3
Re: String sort in Alphabetical order
Do you have some code? I'm lazy
-
March 22nd, 2010, 12:16 PM
#4
Re: String sort in Alphabetical order
Nope. Sorry, I don't work for free.
Viggy
-
March 22nd, 2010, 12:23 PM
#5
Re: String sort in Alphabetical order
Check out std::sort in <algorithm>, it was just a google away
http://www.cplusplus.com/reference/algorithm/sort/
your humble savant
-
March 22nd, 2010, 12:27 PM
#6
Re: String sort in Alphabetical order
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.
-
March 22nd, 2010, 02:00 PM
#7
Re: String sort in Alphabetical order
What result do you want for the string "cbaCBA"? In other words, are you looking for a case-invariant sort?
-
March 22nd, 2010, 02:39 PM
#8
Re: String sort in Alphabetical order
Its only caps.
so for example i need to sort the string "TEST" to "ESTT".
-
March 22nd, 2010, 04:27 PM
#9
Re: String sort in Alphabetical order
Great, then you don't even need to write a custom comparator for std::sort.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|