Insertion Sorting c#

前端 未结 3 773
暗喜
暗喜 2021-01-29 12:10

Can you guys please help me with basic insertion sorting in C#. I have a list of names and city of residence in a array and need to sort this array by comparing the city of resi

3条回答
  •  余生分开走
    2021-01-29 12:54

    Try like this...

    public void InsertionSort()
    {
        for (int i = 0; i < Count; i++)
        {
            int j = i;
            While(j > 0)
            {
                Student cur = Attendees[j];
                Student sel = Attendees[j-1];
                if (cur.CompareTo(Sel) < 0)
                {
                    Student temp = cur;
                    cur = sel;
                    sel = temp;
                    j--
                }
                else
                    break;
            }
        }
    }
    

提交回复
热议问题