以下のコード。アイデアは、姓の配列を並べ替え、姓に関連してすべてのデータを移動させることです。そのため、サンプル データは次のとおりです。
Amy Wilson 21 68.5 190 150 10
Scott Wilson 25 76.5 250 210 10
Jamie Scott 45 62 150 135 56
Sharon Baxter 52 65 150 140 8
Brock Stanley 65 70 180 190 4
Baxter Cash 18 72 170 200 8
John Stanford 30 74 190 210 7
Angel Delgado 25 62.5 150 137 5
Brad Harris 55 70 200 180 6
Amber Carrell 18 65 120 110 3
Jakob Neihaus 20 64 110 120 3
Willie Mitchell 23 68 150 170 6
Melia Mugano 18 67 167 145 7
そして、これがソートされたように見えるはずです:
Sharon Baxter 52 65 150 140 8
Amber Carrell 18 65 120 110 3
Baxter Cash 18 72 170 200 8
Angel Delgado 25 62.5 150 137 5
Brad Harris 55 70 200 180 6
Willie Mitchell 23 68 150 170 6
Melia Mugano 18 67 167 145 7
Jakob Neihaus 20 64 110 120 3
Jamie Scott 45 62 150 135 56
John Stanford 30 74 190 210 7
Brock Stanley 65 70 180 190 4
Amy Wilson 21 68.5 190 150 10
Scott Wilson 25 76.5 250 210 10
これが私が得ているものです
Sharon Baxter 52 68.5 190 150 10
Amber Carrell 18 76.5 250 210 10
Baxter Cash 18 62 150 135 56
Angel Delgado 25 65 150 140 8
Brad Harris 55 70 180 190 4
Willie Mitchell 23 72 170 200 8
Melia Mugano 18 74 190 210 7
Jakob Neihaus 20 62.5 150 137 5
Jamie Scott 45 70 200 180 6
John Stanford 30 65 120 110 3
Brock Stanley 65 64 110 120 3
Amy Wilson 21 67 167 145 7
Scott Wilson 25 68 150 170 6
もう一度並べ替えるときの追加の問題として、Amy と Scott Wilson が場所を入れ替えると、残りのデータはすべて並べ替えられたままになります。
私は何を間違っていますか?
コード:
private void sortArray()
{
string[] clientFirstnameArray = new string[mMaxClients];
string[] clientLastnameArray = new string[mMaxClients];
int[] clientAgeArray = new int[mMaxClients];
double[] clientHeightArray = new double[mMaxClients];
double[] clientStartWeightArray = new double[mMaxClients];
double[] goalWeightArray = new double[mMaxClients];
int[] weeksArray = new int[mMaxClients];
for (int index = 0; index < mNumClient; index++)
{
clientLastnameArray[index] = mClients[index].LastName;
clientFirstnameArray[index] = mClients[index].FirstName;
clientAgeArray[index] = mClients[index].Age;
clientHeightArray[index] = mClients[index].Height;
clientStartWeightArray[index] = mClients[index].StartWeight;
goalWeightArray[index] = mClients[index].GoalWeight;
weeksArray[index] = mClients[index].Weeks;
}
string[] copy_clientLastnameArray = new string[mMaxClients];
Array.Copy(clientLastnameArray, 0, copy_clientLastnameArray, 0, mNumClient);
Array.Sort(clientLastnameArray, clientFirstnameArray, 0, mNumClient);
Array.Sort(copy_clientLastnameArray, clientAgeArray, 0, mNumClient);
Array.Sort(copy_clientLastnameArray, clientHeightArray, 0, mNumClient);
Array.Sort(copy_clientLastnameArray, clientStartWeightArray, 0, mNumClient);
Array.Sort(copy_clientLastnameArray, goalWeightArray, 0, mNumClient);
Array.Sort(copy_clientLastnameArray, weeksArray, 0, mNumClient);
for (int index = 0; index < mNumClient; index++)
{
mClients[index].LastName = clientLastnameArray[index];
mClients[index].FirstName = clientFirstnameArray[index];
mClients[index].Age = clientAgeArray[index];
mClients[index].Height = clientHeightArray[index];
mClients[index].StartWeight = clientStartWeightArray[index];
mClients[index].GoalWeight = goalWeightArray[index];
mClients[index].Weeks = weeksArray[index];
}
}