C# での基本的な挿入ソートについて教えてください。配列に名前と居住都市のリストがあり、居住都市を比較してこの配列をソートする必要があります。リストはアルファベット順にソートする必要があります。Comparator がセットアップされ、動作します。挿入ソーターのプログラミングは、この方法で行うのは初めてなので、少し戸惑っています。
これが私がこれまでに試したことです:
public void InsertionSort()
{
for (int i = 0; i < Count; i++)
{
Student cur = Attendees[i];
for (int j = 0; j < Count; j++)
{
Student Sel = Attendees[j];
if (cur.CompareTo(Sel) < 0)
{
Student temp = Attendees[j];
Attendees[j] = Attendees[i];
for (int k = i; k > j; k--)
Attendees[k] = Attendees[k - 1];
Attendees[k + 1] = temp;
}
}
}
}