인터넷 및 서적을 검색했지만 운이 없었으므로 누군가가 올바른 방향으로 나를 가리킬 수 있기를 바랍니다.삽입 정렬 알고리즘을 사용하여 알파벳 순 정렬 C#
기본적으로 객체는 내장 된 방법이 아닌 삽입 정렬을 사용하여 사전 순으로 이름 문으로 정렬해야합니다. 배열 및 목록을 사용하여 시도했지만 작동하도록 할 수 없습니다. 그 일에 대해 어떻게 생각하세요?
내가 플레이어의 클래스가, 목록 작성 최근의 시도는 객체 : 사용자가
가 나는 다음 코드를 사용하려고 해요를 정렬하려면 개체를
public static List<Player> user = new List<Player>();
private string name; //Read and Write
private int score; //Read and Write
private double health; //Read and Write
private int level; //Read and Write
public string[] inventory = new string[30];
public void setName(String newName)
{
name = newName;
}
public string getName()
{
return name;
}
public void setScore(int newScore)
{
score = newScore;
}
public int getScore()
{
return score;
}
public void setHealth(double newHealth)
{
health = newHealth;
}
public double getHealth()
{
return health;
}
public void setLevel(int newLevel)
{
level = newLevel;
}
public int getLevel()
{
return level;
}
public static void Saved_Player()
{
user.Add(new Player() { name = "Timid Bob", health = 63, level = 6, score = 2000, });
user[0].inventory[0] = "Steel Sword";
user[0].inventory[1] = "1mm MAW";
user[0].inventory[2] = "Short Bow";
user[0].inventory[0] = "Grenade";
user.Add(new Player() {name = "Killer Bob", health = 82, level = 2, score = 1050000, });
user[1].inventory[0] = "Glass Sword";
user[1].inventory[1] = "250mm MAW";
user[1].inventory[2] = "Elephant Bow";
user[1].inventory[3] = "Rock";
등등 ... 6 개까지 또 다른 Form1 클래스 :
권리 // sudo는 코드
for(int i = 0; i < Player.user.Count; i++)
{
while (i index is higher than i+1 index)
{
swap i index with i+1 index
}
}
희망 :/
PublicJoe가 어떻게 수행했는지는 알 것 같지만 객체 인덱스를 얻고 설정하는 방법은 무엇입니까? 보고 주셔서 감사합니다.
숙제를? 작동하지 않는 것은 무엇입니까? 코드를 게시하십시오. –
http://www.publicjoe.f9.co.uk/csharp/sort00.html – Josh
질문을 편집하여 지금까지의 최선의 시도를 포함하고 그것이 효과가 없다고 생각하는 이유를 설명하면, 도와주세요. –