我想写给出以下结构的程序:排序字符串数组按字母C++
struct aPlayer {
string name; // name of player
int wins; // number of wins player has
};
struct aCompetition {
string name; // name of the match
int numPlayers; // number of players in the club
aPlayer player[10]; // list of players in this club
};
从那里我想写,将字母排列顺序玩家进行排序的功能。该函数的声明将如下所示:
void sortByName(aCompetition & c){}
注:我想通过只使用循环来做到这一点,while循环,如果声明(S)。我能想到比较两个字符串的唯一方法是比较它们的ASCII值。我不知道如何做到这一点,所以任何输入将不胜感激。谢谢!
的std :: string支持小于和大于比较。我会使用std :: sort,但是如果你只限于你可以使用的简单的冒泡排序,那么很好,你可以很容易地找到该算法。 –
aCompetition应该是一个结构吗?考虑到它拥有一个数组? – Krythic
似乎完全正常于我。比赛包含球员。 –