Sorting alpha characters, not ASCII?

Nov 7, 2013 at 2:52am
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!!
Nov 7, 2013 at 2:54am
Nov 7, 2013 at 3:02am
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.
Nov 7, 2013 at 3:04am
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 Nov 7, 2013 at 3:05am
Nov 7, 2013 at 3:05am
And that would sort it like AaABbB as AAaBBb instead of AABBab?
Nov 7, 2013 at 3:09am
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 Nov 7, 2013 at 3:14am
Nov 7, 2013 at 3:10am
Actually, depending on the underlying sorting algorithm, "AaABbB" could be left unchanged by LB's function.
Nov 7, 2013 at 11:56pm
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.