I need to know how to sort an array of Strings, I know how to do a selection sort, however I have BOTH numbers and letters in the array. The idea is to sort a hand of cards. This is what I have ...
clubsArry[0] = 7C
clubsArry[1] = AC
clubsArry[2] = TC
clubsArry[3] = KC
The second character represents the suit of the card, in this case clubs, and the first character is the card value (the T represents Ten, K is king, A is ace, etc.), so for the clubsArry[0] , the card is a 7 of clubs. When I sort it and print, the output I get is ....
7C
AC
KC
TC
So all the cards that that have a letter in the first position get sorted properly but I still have the 7 of clubs that is at the top of the output. The output that I want is ...
AC
KC
TC
7C
The way I tried to sort it was by doing this:
public void sortClubs() // A selection sort, that will sort out the clubs
{
for (int i = 1; i < clubsArry.length; i++)
{
int s = i-1;
for (int j = i; j < clubsArry.length; j++)
{
if (clubsArry[j].compareTo(clubsArry[s]) < 0)
{
s = j;
}
}
String temp = clubsArry[i-1];
clubsArry[i-1] = clubsArry[s];
clubsArry[s] = temp;
}
}
I just cant seem to figure it out, I was going to convert it into a char array and then cast into an int and the sort and convert it all back, but I figure there must be a simpler way to do this, If there is a way at all.
Thanks for all the help :)
MadcapClover
1or11? lol (also, refer to the Episode of Chuck)