Sorting alpha characters, not ASCII?

Hey guys, I am looking for a way to sort a string just by the alpha characters, not by the ASCII table. Therefore
1
2
3
4
5
6
string sort(string name)
{
    sort(name.begin(), name.end());
    
    return name;
}


will not work.

And I am looking for the most simple way to go about it! Thanks!!
Yes, but I cannot use vector as we have not learned it in class yet. I am personally a little familiar with them but he has not taught us yet.
std::sort works in plain arrays too, just give the array itself as the first parameter and the array itself plus the size of the array for the second parameter.

(Also, I'm a bit disappointed that your professor is teaching you plain arrays before std::vector - hoepfully he didn't also teach you c-style strings before std::string?)
Last edited on
And that would sort it like AaABbB as AAaBBb instead of AABBab?
I think I misunderstood. You want to sort the characters inside a single string, right?

http://ideone.com/j2MkQI

Technically, it is already sorted, as helios has mentioned below.
Last edited on
Actually, depending on the underlying sorting algorithm, "AaABbB" could be left unchanged by LB's function.
My professor actually hasn't really taught us arrays either yet. I am familiar with them, we just haven't reached them. Also, AaABbB isn't my actual string lol I was using that as an example.

Also, we use using namespace std; so std:: isn't much of use for us. He also talks a crap load about other stuff we have no idea about because he has ADHD
Topic archived. No new replies allowed.